Skip to content

Commit 9cce7f5

Browse files
committed
Fix issue where a line break within an HTML tag's attribute value could cause the tag to not be parsed correctly.
1 parent 07038c7 commit 9cce7f5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/HtmlParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Autolinker.HtmlParser = Autolinker.Util.extend( Object, {
2727
htmlRegex : (function() {
2828
var tagNameRegex = /[0-9a-zA-Z][0-9a-zA-Z:]*/,
2929
attrNameRegex = /[^\s\0"'>\/=\x01-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
30-
attrValueRegex = /(?:".*?"|'.*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
30+
attrValueRegex = /(?:"[^"]*?"|'[^']*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
3131
nameEqualsValueRegex = attrNameRegex.source + '(?:\\s*=\\s*' + attrValueRegex.source + ')?'; // optional '=[value]'
3232

3333
return new RegExp( [

tests/AutolinkerSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,14 @@ describe( "Autolinker", function() {
10081008
var result = autolinker.link( html );
10091009
expect( result ).toBe( '<p>Joe went to <a href="http://example.com?arg=1&arg=2&arg=3">example.com?arg=1&amp;arg=2&amp;arg=3</a></p>' );
10101010
} );
1011+
1012+
1013+
it( "should handle line breaks inside an HTML tag, not accidentally autolinking a URL within the tag", function() {
1014+
var html = '<a href="http://close.io/" style="font-family: Helvetica,\nArial">http://close.io</a>';
1015+
1016+
var result = autolinker.link( html );
1017+
expect( result ).toBe( '<a href="http://close.io/" style="font-family: Helvetica,\nArial">http://close.io</a>' );
1018+
} );
10111019

10121020
} );
10131021

0 commit comments

Comments
 (0)