Skip to content

Commit

Permalink
Fix issue where a line break within an HTML tag's attribute value cou…
Browse files Browse the repository at this point in the history
…ld cause the tag to not be parsed correctly.
  • Loading branch information
gregjacobs committed Jan 4, 2015
1 parent 07038c7 commit 9cce7f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HtmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Autolinker.HtmlParser = Autolinker.Util.extend( Object, {
htmlRegex : (function() {
var tagNameRegex = /[0-9a-zA-Z][0-9a-zA-Z:]*/,
attrNameRegex = /[^\s\0"'>\/=\x01-\x1F\x7F]+/, // the unicode range accounts for excluding control chars, and the delete char
attrValueRegex = /(?:".*?"|'.*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
attrValueRegex = /(?:"[^"]*?"|'[^']*?'|[^'"=<>`\s]+)/, // double quoted, single quoted, or unquoted attribute values
nameEqualsValueRegex = attrNameRegex.source + '(?:\\s*=\\s*' + attrValueRegex.source + ')?'; // optional '=[value]'

return new RegExp( [
Expand Down
8 changes: 8 additions & 0 deletions tests/AutolinkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,14 @@ describe( "Autolinker", function() {
var result = autolinker.link( html );
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>' );
} );


it( "should handle line breaks inside an HTML tag, not accidentally autolinking a URL within the tag", function() {
var html = '<a href="http://close.io/" style="font-family: Helvetica,\nArial">http://close.io</a>';

var result = autolinker.link( html );
expect( result ).toBe( '<a href="http://close.io/" style="font-family: Helvetica,\nArial">http://close.io</a>' );
} );

} );

Expand Down

0 comments on commit 9cce7f5

Please sign in to comment.