Skip to content

Commit a653006

Browse files
committed
Build 1.6.2
1 parent fb31497 commit a653006

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

dist/Autolinker.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Autolinker.js
3-
* 1.6.1
3+
* 1.6.2
44
*
55
* Copyright(c) 2018 Gregory Jacobs <[email protected]>
66
* MIT License
@@ -241,7 +241,7 @@ Autolinker.parse = function( textOrHtml, options ) {
241241
*
242242
* Ex: 0.25.1
243243
*/
244-
Autolinker.version = '1.6.1';
244+
Autolinker.version = '1.6.2';
245245

246246

247247
Autolinker.prototype = {
@@ -1558,13 +1558,19 @@ Autolinker.RegexLib = (function() {
15581558
var alphaNumericCharsStr = alphaCharsStr + decimalNumbersStr;
15591559

15601560
// Simplified IP regular expression
1561-
var ipRegex = new RegExp( '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}' );
1561+
var ipStr = '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}';
15621562

15631563
// Protected domain label which do not allow "-" character on the beginning and the end of a single label
1564-
var domainLabelStr = '[' + alphaNumericCharsStr + '](?:[' + alphaNumericCharsStr + '\\-]*[' + alphaNumericCharsStr + '])?';
1564+
var domainLabelStr = '[' + alphaNumericCharsStr + '](?:[' + alphaNumericCharsStr + '\\-]{0,61}[' + alphaNumericCharsStr + '])?';
1565+
1566+
var getDomainLabelStr = function(group) {
1567+
return '(?=(' + domainLabelStr + '))\\' + group;
1568+
};
15651569

15661570
// See documentation below
1567-
var domainNameRegex = new RegExp( '(?:(?:(?:' + domainLabelStr + '\\.)*(?:' + domainLabelStr + '))|(?:' + ipRegex.source + '))' );
1571+
var getDomainNameStr = function(group) {
1572+
return '(?:' + getDomainLabelStr(group) + '(?:\\.' + getDomainLabelStr(group + 1) + '){0,126}|' + ipStr + ')';
1573+
};
15681574

15691575
return {
15701576

@@ -1598,7 +1604,7 @@ Autolinker.RegexLib = (function() {
15981604
*
15991605
* @property {RegExp} domainNameRegex
16001606
*/
1601-
domainNameRegex : domainNameRegex,
1607+
getDomainNameStr : getDomainNameStr,
16021608

16031609
};
16041610

@@ -3264,12 +3270,12 @@ Autolinker.matcher.Email = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
32643270
validCharacters = alphaNumericChars + specialCharacters,
32653271
validRestrictedCharacters = validCharacters + restrictedSpecialCharacters,
32663272
emailRegex = new RegExp( '(?:[' + validCharacters + '](?:[' + validCharacters + ']|\\.(?!\\.|@))*|\\"[' + validRestrictedCharacters + '.]+\\")@'),
3267-
domainNameRegex = Autolinker.RegexLib.domainNameRegex,
3273+
getDomainNameStr = Autolinker.RegexLib.getDomainNameStr,
32683274
tldRegex = Autolinker.tldRegex; // match our known top level domains (TLDs)
32693275

32703276
return new RegExp( [
32713277
emailRegex.source,
3272-
domainNameRegex.source,
3278+
getDomainNameStr(1),
32733279
'\\.', tldRegex.source // '.com', '.net', etc
32743280
].join( "" ), 'gi' );
32753281
} )(),
@@ -3600,9 +3606,9 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
36003606
* See #3 for more info.
36013607
*/
36023608
matcherRegex : (function() {
3603-
var schemeRegex = /(?:[A-Za-z][-.+A-Za-z0-9]*:(?![A-Za-z][-.+A-Za-z0-9]*:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
3609+
var schemeRegex = /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
36043610
wwwRegex = /(?:www\.)/, // starting with 'www.'
3605-
domainNameRegex = Autolinker.RegexLib.domainNameRegex,
3611+
getDomainNameStr = Autolinker.RegexLib.getDomainNameStr,
36063612
tldRegex = Autolinker.tldRegex, // match our known top level domains (TLDs)
36073613
alphaNumericCharsStr = Autolinker.RegexLib.alphaNumericCharsStr,
36083614

@@ -3614,22 +3620,22 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
36143620
'(?:', // parens to cover match for scheme (optional), and domain
36153621
'(', // *** Capturing group $1, for a scheme-prefixed url (ex: http://google.com)
36163622
schemeRegex.source,
3617-
domainNameRegex.source,
3623+
getDomainNameStr(2),
36183624
')',
36193625

36203626
'|',
36213627

3622-
'(', // *** Capturing group $2, for a 'www.' prefixed url (ex: www.google.com)
3623-
'(//)?', // *** Capturing group $3 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character (handled later)
3628+
'(', // *** Capturing group $4 for a 'www.' prefixed url (ex: www.google.com)
3629+
'(//)?', // *** Capturing group $5 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character (handled later)
36243630
wwwRegex.source,
3625-
domainNameRegex.source,
3631+
getDomainNameStr(6),
36263632
')',
36273633

36283634
'|',
36293635

3630-
'(', // *** Capturing group $4, for known a TLD url (ex: google.com)
3631-
'(//)?', // *** Capturing group $5 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character (handled later)
3632-
domainNameRegex.source + '\\.',
3636+
'(', // *** Capturing group $8, for known a TLD url (ex: google.com)
3637+
'(//)?', // *** Capturing group $9 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character (handled later)
3638+
getDomainNameStr(10) + '\\.',
36333639
tldRegex.source,
36343640
'(?![-' + alphaNumericCharsStr + '])', // TLD not followed by a letter, behaves like unicode-aware \b
36353641
')',
@@ -3716,10 +3722,10 @@ Autolinker.matcher.Url = Autolinker.Util.extend( Autolinker.matcher.Matcher, {
37163722
while( ( match = matcherRegex.exec( text ) ) !== null ) {
37173723
var matchStr = match[ 0 ],
37183724
schemeUrlMatch = match[ 1 ],
3719-
wwwUrlMatch = match[ 2 ],
3720-
wwwProtocolRelativeMatch = match[ 3 ],
3721-
//tldUrlMatch = match[ 4 ], -- not needed at the moment
3722-
tldProtocolRelativeMatch = match[ 5 ],
3725+
wwwUrlMatch = match[ 4 ],
3726+
wwwProtocolRelativeMatch = match[ 5 ],
3727+
//tldUrlMatch = match[ 8 ], -- not needed at the moment
3728+
tldProtocolRelativeMatch = match[ 9 ],
37233729
offset = match.index,
37243730
protocolRelativeMatch = wwwProtocolRelativeMatch || tldProtocolRelativeMatch,
37253731
prevChar = text.charAt( offset - 1 );

dist/Autolinker.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/Autolinker.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,11 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
18331833
tagNameRegex = /[0-9a-zA-Z][0-9a-zA-Z:]*/,
18341834
attrNameRegex = /[^\s"'>\/=\x00-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
18351835
attrValueRegex = /(?:"[^"]*?"|'[^']*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
1836-
nameEqualsValueRegex = attrNameRegex.source + '(?:\\s*=\\s*' + attrValueRegex.source + ')?'; // optional '=[value]'
1836+
optionalAttrValueRegex = '(?:\\s*?=\\s*?' + attrValueRegex.source + ')?'; // optional '=[value]'
1837+
1838+
var getNameEqualsValueRegex = function(group) {
1839+
return '(?=(' + attrNameRegex.source + '))\\' + group + optionalAttrValueRegex;
1840+
};
18371841

18381842
return new RegExp( [
18391843
// for <!DOCTYPE> tag. Ex: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">)
@@ -1847,7 +1851,8 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
18471851
// Either:
18481852
// A. attr="value", or
18491853
// B. "value" alone (To cover example doctype tag: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">)
1850-
'(?:', nameEqualsValueRegex, '|', attrValueRegex.source + ')',
1854+
// *** Capturing Group 2 - Pseudo-atomic group for attrNameRegex
1855+
'(?:', getNameEqualsValueRegex(2), '|', attrValueRegex.source + ')',
18511856
')*',
18521857
'>',
18531858
')',
@@ -1857,10 +1862,10 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
18571862
// All other HTML tags (i.e. tags that are not <!DOCTYPE>)
18581863
'(?:',
18591864
'<(/)?', // Beginning of a tag or comment. Either '<' for a start tag, or '</' for an end tag.
1860-
// *** Capturing Group 2: The slash or an empty string. Slash ('/') for end tag, empty string for start or self-closing tag.
1865+
// *** Capturing Group 3: The slash or an empty string. Slash ('/') for end tag, empty string for start or self-closing tag.
18611866

18621867
'(?:',
1863-
commentTagRegex.source, // *** Capturing Group 3 - A Comment Tag's Text
1868+
commentTagRegex.source, // *** Capturing Group 4 - A Comment Tag's Text
18641869

18651870
'|',
18661871

@@ -1869,7 +1874,7 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
18691874
// to fix a regex time complexity issue seen with the
18701875
// example in https://github.com/gregjacobs/Autolinker.js/issues/172
18711876
'(?:',
1872-
// *** Capturing Group 4 - The tag name for a tag without attributes
1877+
// *** Capturing Group 5 - The tag name for a tag without attributes
18731878
'(' + tagNameRegex.source + ')',
18741879

18751880
'\\s*/?', // any trailing spaces and optional '/' before the closing '>'
@@ -1882,15 +1887,16 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
18821887
// to fix a regex time complexity issue seen with the
18831888
// example in https://github.com/gregjacobs/Autolinker.js/issues/172
18841889
'(?:',
1885-
// *** Capturing Group 5 - The tag name for a tag with attributes
1890+
// *** Capturing Group 6 - The tag name for a tag with attributes
18861891
'(' + tagNameRegex.source + ')',
18871892

18881893
'\\s+', // must have at least one space after the tag name to prevent ReDoS issue (issue #172)
18891894

18901895
// Zero or more attributes following the tag name
18911896
'(?:',
18921897
'(?:\\s+|\\b)', // any number of whitespace chars before an attribute. NOTE: Using \s* here throws Chrome into an infinite loop for some reason, so using \s+|\b instead
1893-
nameEqualsValueRegex, // attr="value" (with optional ="value" part)
1898+
// *** Capturing Group 7 - Pseudo-atomic group for attrNameRegex
1899+
getNameEqualsValueRegex(7), // attr="value" (with optional ="value" part)
18941900
')*',
18951901

18961902
'\\s*/?', // any trailing spaces and optional '/' before the closing '>'
@@ -1928,9 +1934,9 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
19281934

19291935
while( ( currentResult = htmlRegex.exec( html ) ) !== null ) {
19301936
var tagText = currentResult[ 0 ],
1931-
commentText = currentResult[ 3 ], // if we've matched a comment
1932-
tagName = currentResult[ 1 ] || currentResult[ 4 ] || currentResult[ 5 ], // The <!DOCTYPE> tag (ex: "!DOCTYPE"), or another tag (ex: "a" or "img")
1933-
isClosingTag = !!currentResult[ 2 ],
1937+
commentText = currentResult[ 4 ], // if we've matched a comment
1938+
tagName = currentResult[ 1 ] || currentResult[ 5 ] || currentResult[ 6 ], // The <!DOCTYPE> tag (ex: "!DOCTYPE"), or another tag (ex: "a" or "img")
1939+
isClosingTag = !!currentResult[ 3 ],
19341940
offset = currentResult.index,
19351941
inBetweenTagsText = html.substring( lastIndex, offset );
19361942

docs/dist/Autolinker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autolinker",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Utility to automatically link the URLs, email addresses, phone numbers, hashtags, and mentions (Twitter, Instagram) in a given block of text/HTML",
55
"main": "dist/Autolinker.js",
66
"files": [

0 commit comments

Comments
 (0)