1
1
/*!
2
2
* Autolinker.js
3
- * 1.4.3
3
+ * 1.4.4
4
4
*
5
5
* Copyright(c) 2017 Gregory Jacobs <greg@greg-jacobs.com>
6
6
* MIT License
@@ -240,7 +240,7 @@ Autolinker.parse = function( textOrHtml, options ) {
240
240
*
241
241
* Ex: 0.25.1
242
242
*/
243
- Autolinker . version = '1.4.3 ' ;
243
+ Autolinker . version = '1.4.4 ' ;
244
244
245
245
246
246
Autolinker . prototype = {
@@ -1546,9 +1546,14 @@ Autolinker.RegexLib = (function() {
1546
1546
// See documentation below
1547
1547
var alphaNumericCharsStr = alphaCharsStr + decimalNumbersStr ;
1548
1548
1549
+ // Simplified IP regular expression
1550
+ var ipRegex = new RegExp ( '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}' ) ;
1551
+
1552
+ // Protected domain label which do not allow "-" character on the beginning and the end of a single label
1553
+ var domainLabelStr = '[' + alphaNumericCharsStr + '](?:[' + alphaNumericCharsStr + '\\-]*[' + alphaNumericCharsStr + '])?' ;
1549
1554
1550
1555
// See documentation below
1551
- var domainNameRegex = new RegExp ( '[ ' + alphaNumericCharsStr + '.\\-]*[ ' + alphaNumericCharsStr + '\\-] ' ) ;
1556
+ var domainNameRegex = new RegExp ( '(?:(?:(?: ' + domainLabelStr + '\\.)*(?: ' + domainLabelStr + '))|(?:' + ipRegex . source + ')) ' ) ;
1552
1557
1553
1558
return {
1554
1559
@@ -3206,7 +3211,11 @@ Autolinker.matcher.Email = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
3206
3211
*/
3207
3212
matcherRegex : ( function ( ) {
3208
3213
var alphaNumericChars = Autolinker . RegexLib . alphaNumericCharsStr ,
3209
- emailRegex = new RegExp ( '[' + alphaNumericChars + '\\-_\';:&=+$.,]+@' ) , // something@ for email addresses (a.k.a. local-part)
3214
+ specialCharacters = '!#$%&\'*+\\-\\/=?^_`{|}~' ,
3215
+ restrictedSpecialCharacters = '\\s"(),:;<>@\\[\\]' ,
3216
+ validCharacters = alphaNumericChars + specialCharacters ,
3217
+ validRestrictedCharacters = validCharacters + restrictedSpecialCharacters ,
3218
+ emailRegex = new RegExp ( '(?:(?:[' + validCharacters + '](?![^@]*\\.\\.)(?:[' + validCharacters + '.]*[' + validCharacters + '])?)|(?:\\"[' + validRestrictedCharacters + '.]+\\"))@' ) ,
3210
3219
domainNameRegex = Autolinker . RegexLib . domainNameRegex ,
3211
3220
tldRegex = Autolinker . tldRegex ; // match our known top level domains (TLDs)
3212
3221
@@ -3373,7 +3382,7 @@ Autolinker.matcher.Phone = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
3373
3382
var matchedText = match [ 0 ] ,
3374
3383
cleanNumber = matchedText . replace ( / [ ^ 0 - 9 , ; # ] / g, '' ) , // strip out non-digit characters exclude comma semicolon and #
3375
3384
plusSign = ! ! match [ 1 ] ; // match[ 1 ] is the prefixed plus sign, if there is one
3376
- if ( / \D / . test ( match [ 2 ] ) && / \D / . test ( matchedText ) ) {
3385
+ if ( this . testMatch ( match [ 2 ] ) && this . testMatch ( matchedText ) ) {
3377
3386
matches . push ( new Autolinker . match . Phone ( {
3378
3387
tagBuilder : tagBuilder ,
3379
3388
matchedText : matchedText ,
@@ -3385,9 +3394,14 @@ Autolinker.matcher.Phone = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
3385
3394
}
3386
3395
3387
3396
return matches ;
3397
+ } ,
3398
+
3399
+ testMatch : function ( text ) {
3400
+ return / \D / . test ( text ) ;
3388
3401
}
3389
3402
3390
3403
} ) ;
3404
+
3391
3405
/*global Autolinker */
3392
3406
/**
3393
3407
* @class Autolinker.matcher.Mention
0 commit comments