Skip to content

Commit c691235

Browse files
committed
Filter out 'javascript:' and 'vbscript:' schemes from being autolinked.
1 parent 2479a45 commit c691235

File tree

5 files changed

+118
-66
lines changed

5 files changed

+118
-66
lines changed

dist/Autolinker.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/*!
1818
* Autolinker.js
19-
* 0.14.0
19+
* 0.14.1
2020
*
2121
* Copyright(c) 2014 Gregory Jacobs <[email protected]>
2222
* MIT Licensed. http://www.opensource.org/licenses/mit-license.php
@@ -1284,6 +1284,7 @@
12841284

12851285
} );
12861286
/*global Autolinker */
1287+
/*jshint scripturl:true */
12871288
/**
12881289
* @private
12891290
* @class Autolinker.MatchValidator
@@ -1322,12 +1323,14 @@
13221323
hasFullProtocolRegex : /^[A-Za-z][-.+A-Za-z0-9]+:\/\//,
13231324

13241325
/**
1325-
* Regex to test for a protocol prefix, such as 'mailto:'
1326+
* Regex to find the URI scheme, such as 'mailto:'.
1327+
*
1328+
* This is used to filter out 'javascript:' and 'vbscript:' schemes.
13261329
*
13271330
* @private
1328-
* @property {RegExp} hasProtocolPrefixRegex
1331+
* @property {RegExp} uriSchemeRegex
13291332
*/
1330-
hasProtocolPrefixRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/,
1333+
uriSchemeRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/,
13311334

13321335
/**
13331336
* Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
@@ -1361,6 +1364,7 @@
13611364
*/
13621365
isValidMatch : function( urlMatch, protocolUrlMatch, protocolRelativeMatch ) {
13631366
if(
1367+
( protocolUrlMatch && !this.isValidUriScheme( protocolUrlMatch ) ) ||
13641368
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
13651369
this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch, protocolUrlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
13661370
this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
@@ -1372,6 +1376,22 @@
13721376
},
13731377

13741378

1379+
/**
1380+
* Determines if the URI scheme is a valid scheme to be autolinked. Returns `false` if the scheme is
1381+
* 'javascript:' or 'vbscript:'
1382+
*
1383+
* @private
1384+
* @param {String} uriSchemeMatch The match URL string for a full URI scheme match. Ex: 'http://yahoo.com'
1385+
* or 'mailto:[email protected]'.
1386+
* @return {Boolean} `true` if the scheme is a valid one, `false` otherwise.
1387+
*/
1388+
isValidUriScheme : function( uriSchemeMatch ) {
1389+
var uriScheme = uriSchemeMatch.match( this.uriSchemeRegex )[ 0 ];
1390+
1391+
return ( uriScheme !== 'javascript:' && uriScheme !== 'vbscript:' );
1392+
},
1393+
1394+
13751395
/**
13761396
* Determines if a URL match does not have either:
13771397
*

0 commit comments

Comments
 (0)