@@ -1833,7 +1833,11 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1833
1833
tagNameRegex = / [ 0 - 9 a - z A - Z ] [ 0 - 9 a - z A - Z : ] * / ,
1834
1834
attrNameRegex = / [ ^ \s " ' > \/ = \x00 - \x1F \x7F ] + / , // the unicode range accounts for excluding control chars, and the delete char
1835
1835
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
+ } ;
1837
1841
1838
1842
return new RegExp ( [
1839
1843
// 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, {
1847
1851
// Either:
1848
1852
// A. attr="value", or
1849
1853
// 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 + ')' ,
1851
1856
')*' ,
1852
1857
'>' ,
1853
1858
')' ,
@@ -1857,10 +1862,10 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1857
1862
// All other HTML tags (i.e. tags that are not <!DOCTYPE>)
1858
1863
'(?:' ,
1859
1864
'<(/)?' , // 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.
1861
1866
1862
1867
'(?:' ,
1863
- commentTagRegex . source , // *** Capturing Group 3 - A Comment Tag's Text
1868
+ commentTagRegex . source , // *** Capturing Group 4 - A Comment Tag's Text
1864
1869
1865
1870
'|' ,
1866
1871
@@ -1869,7 +1874,7 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1869
1874
// to fix a regex time complexity issue seen with the
1870
1875
// example in https://github.com/gregjacobs/Autolinker.js/issues/172
1871
1876
'(?:' ,
1872
- // *** Capturing Group 4 - The tag name for a tag without attributes
1877
+ // *** Capturing Group 5 - The tag name for a tag without attributes
1873
1878
'(' + tagNameRegex . source + ')' ,
1874
1879
1875
1880
'\\s*/?' , // any trailing spaces and optional '/' before the closing '>'
@@ -1882,15 +1887,16 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1882
1887
// to fix a regex time complexity issue seen with the
1883
1888
// example in https://github.com/gregjacobs/Autolinker.js/issues/172
1884
1889
'(?:' ,
1885
- // *** Capturing Group 5 - The tag name for a tag with attributes
1890
+ // *** Capturing Group 6 - The tag name for a tag with attributes
1886
1891
'(' + tagNameRegex . source + ')' ,
1887
1892
1888
1893
'\\s+' , // must have at least one space after the tag name to prevent ReDoS issue (issue #172)
1889
1894
1890
1895
// Zero or more attributes following the tag name
1891
1896
'(?:' ,
1892
1897
'(?:\\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)
1894
1900
')*' ,
1895
1901
1896
1902
'\\s*/?' , // any trailing spaces and optional '/' before the closing '>'
@@ -1928,9 +1934,9 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1928
1934
1929
1935
while ( ( currentResult = htmlRegex . exec ( html ) ) !== null ) {
1930
1936
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 ] ,
1934
1940
offset = currentResult . index ,
1935
1941
inBetweenTagsText = html . substring ( lastIndex , offset ) ;
1936
1942
0 commit comments