Skip to content

Commit abb9f99

Browse files
committed
Merge branch 'Issue_160_Fix_Infinite_Loop'
2 parents 4ed0fdd + e38f68d commit abb9f99

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/htmlParser/HtmlParser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
2929
htmlRegex : (function() {
3030
var commentTagRegex = /!--([\s\S]+?)--/,
3131
tagNameRegex = /[0-9a-zA-Z][0-9a-zA-Z:]*/,
32-
attrNameRegex = /[^\s\0"'>\/=\x01-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
32+
attrNameRegex = /[^\s"'>\/=\x00-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
3333
attrValueRegex = /(?:"[^"]*?"|'[^']*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
3434
nameEqualsValueRegex = attrNameRegex.source + '(?:\\s*=\\s*' + attrValueRegex.source + ')?'; // optional '=[value]'
3535

@@ -69,7 +69,7 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
6969

7070
// Zero or more attributes following the tag name
7171
'(?:',
72-
'\\s*', // any number of whitespace chars before an attribute
72+
'(?:\\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
7373
nameEqualsValueRegex, // attr="value" (with optional ="value" part)
7474
')*',
7575

tests/AutolinkerSpec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,41 @@ describe( "Autolinker", function() {
12491249
} );
12501250

12511251

1252+
it( "should not fail with an infinite loop for these given input strings (Issue #160)", function() {
1253+
var inputStrings = [
1254+
'asdf ouefof<33we oeweofjojfew oeijwffejifjew ojiwjoiwefj iowjefojwe iofjw:)<33',
1255+
'<33<33<33<33<33<33<33<33<33<33',
1256+
'<33<33<33<33<33<33<33<33<33<33<33'
1257+
];
1258+
1259+
inputStrings.forEach( function( str ) {
1260+
expect( autolinker.link( str ) ).toBe( str ); // no links in these, just making sure they don't fail with 100% cpu and an infinite loop
1261+
} );
1262+
} );
1263+
1264+
1265+
it( "should not fail with an infinite loop for an input string with " +
1266+
"completely invalid HTML (issue #160)",
1267+
function() {
1268+
var result = autolinker.link(
1269+
1270+
'He gave me a 1-800 customer care number that I\'ve called twice. The last time I called, about 3 weeks ago, the customer rep said he would request an expedited response. He gave me a reference number which is 925767619. Thankyou very much for looking into this.\n' +
1271+
'\n' +
1272+
'Ronald D Brigham\n' +
1273+
1274+
);
1275+
1276+
expect( result ).toBe( [
1277+
'<<a href="mailto:[email protected]">[email protected]</a>',
1278+
'He gave me a 1-800 customer care number that I\'ve called twice. The last time I called, about 3 weeks ago, the customer rep said he would request an expedited response. He gave me a reference number which is 925767619. Thankyou very much for looking into this.',
1279+
'',
1280+
'Ronald D Brigham',
1281+
'<a href="mailto:[email protected]">[email protected]</a>'
1282+
].join( '\n' ) );
1283+
} );
1284+
1285+
1286+
12521287
it( "should NOT modify the email address with other tags when inside another anchor", function() {
12531288
var input = [
12541289
'<div>First name: Subin</div>',

0 commit comments

Comments
 (0)