11/*!
22 * Autolinker.js
3- * 1.4.3
3+ * 1.4.4
44 *
55 * Copyright(c) 2017 Gregory Jacobs <greg@greg-jacobs.com>
66 * MIT License
@@ -240,7 +240,7 @@ Autolinker.parse = function( textOrHtml, options ) {
240240 *
241241 * Ex: 0.25.1
242242 */
243- Autolinker . version = '1.4.3 ' ;
243+ Autolinker . version = '1.4.4 ' ;
244244
245245
246246Autolinker . prototype = {
@@ -1546,9 +1546,14 @@ Autolinker.RegexLib = (function() {
15461546 // See documentation below
15471547 var alphaNumericCharsStr = alphaCharsStr + decimalNumbersStr ;
15481548
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 + '])?' ;
15491554
15501555 // See documentation below
1551- var domainNameRegex = new RegExp ( '[ ' + alphaNumericCharsStr + '.\\-]*[ ' + alphaNumericCharsStr + '\\-] ' ) ;
1556+ var domainNameRegex = new RegExp ( '(?:(?:(?: ' + domainLabelStr + '\\.)*(?: ' + domainLabelStr + '))|(?:' + ipRegex . source + ')) ' ) ;
15521557
15531558 return {
15541559
@@ -3206,7 +3211,11 @@ Autolinker.matcher.Email = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
32063211 */
32073212 matcherRegex : ( function ( ) {
32083213 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 + '.]+\\"))@' ) ,
32103219 domainNameRegex = Autolinker . RegexLib . domainNameRegex ,
32113220 tldRegex = Autolinker . tldRegex ; // match our known top level domains (TLDs)
32123221
@@ -3373,7 +3382,7 @@ Autolinker.matcher.Phone = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
33733382 var matchedText = match [ 0 ] ,
33743383 cleanNumber = matchedText . replace ( / [ ^ 0 - 9 , ; # ] / g, '' ) , // strip out non-digit characters exclude comma semicolon and #
33753384 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 ) ) {
33773386 matches . push ( new Autolinker . match . Phone ( {
33783387 tagBuilder : tagBuilder ,
33793388 matchedText : matchedText ,
@@ -3385,9 +3394,14 @@ Autolinker.matcher.Phone = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
33853394 }
33863395
33873396 return matches ;
3397+ } ,
3398+
3399+ testMatch : function ( text ) {
3400+ return / \D / . test ( text ) ;
33883401 }
33893402
33903403} ) ;
3404+
33913405/*global Autolinker */
33923406/**
33933407 * @class Autolinker.matcher.Mention
0 commit comments