|
16 | 16 |
|
17 | 17 | /*!
|
18 | 18 | * Autolinker.js
|
19 |
| - * 0.14.0 |
| 19 | + * 0.14.1 |
20 | 20 | *
|
21 | 21 | * Copyright(c) 2014 Gregory Jacobs <[email protected]>
|
22 | 22 | * MIT Licensed. http://www.opensource.org/licenses/mit-license.php
|
|
1284 | 1284 |
|
1285 | 1285 | } );
|
1286 | 1286 | /*global Autolinker */
|
| 1287 | + /*jshint scripturl:true */ |
1287 | 1288 | /**
|
1288 | 1289 | * @private
|
1289 | 1290 | * @class Autolinker.MatchValidator
|
|
1322 | 1323 | hasFullProtocolRegex : /^[A-Za-z][-.+A-Za-z0-9]+:\/\//,
|
1323 | 1324 |
|
1324 | 1325 | /**
|
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. |
1326 | 1329 | *
|
1327 | 1330 | * @private
|
1328 |
| - * @property {RegExp} hasProtocolPrefixRegex |
| 1331 | + * @property {RegExp} uriSchemeRegex |
1329 | 1332 | */
|
1330 |
| - hasProtocolPrefixRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/, |
| 1333 | + uriSchemeRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/, |
1331 | 1334 |
|
1332 | 1335 | /**
|
1333 | 1336 | * Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
|
|
1361 | 1364 | */
|
1362 | 1365 | isValidMatch : function( urlMatch, protocolUrlMatch, protocolRelativeMatch ) {
|
1363 | 1366 | if(
|
| 1367 | + ( protocolUrlMatch && !this.isValidUriScheme( protocolUrlMatch ) ) || |
1364 | 1368 | 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')
|
1365 | 1369 | 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"
|
1366 | 1370 | 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 | 1376 | },
|
1373 | 1377 |
|
1374 | 1378 |
|
| 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 | + |
| 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 | + |
1375 | 1395 | /**
|
1376 | 1396 | * Determines if a URL match does not have either:
|
1377 | 1397 | *
|
|
0 commit comments