Skip to content

Commit 3ec00ca

Browse files
author
Vadim Kazakov
committed
properly handling & character as part of the url
1 parent bb7fd38 commit 3ec00ca

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

dist/Autolinker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@
166166
* @property {RegExp} htmlCharacterEntities
167167
*
168168
* The regular expression that matches common HTML character entities.
169+
*
170+
* Ignoring & as it coule be part of a query string, handling it separately
169171
*/
170-
htmlCharacterEntities: /( | |<|<|>|>|&|&)/i,
172+
htmlCharacterEntities: /( | |<|<|>|>)/i,
171173

172174
/**
173175
* @private
@@ -1018,7 +1020,8 @@
10181020
* @return {String}
10191021
*/
10201022
getAnchorHref : function() {
1021-
return this.getUrl();
1023+
var url = this.getUrl();
1024+
return url.replace('&', '&');
10221025
},
10231026

10241027

dist/Autolinker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Autolinker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ Autolinker.prototype = {
145145
* @property {RegExp} htmlCharacterEntities
146146
*
147147
* The regular expression that matches common HTML character entities.
148+
*
149+
* Ignoring & as it coule be part of a query string, handling it separately
148150
*/
149-
htmlCharacterEntities: /( | |<|<|>|>|&|&)/i,
151+
htmlCharacterEntities: /( | |<|<|>|>)/i,
150152

151153
/**
152154
* @private

src/UrlMatch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Autolinker.UrlMatch = Autolinker.Util.extend( Autolinker.Match, {
7373
* @return {String}
7474
*/
7575
getAnchorHref : function() {
76-
return this.getUrl();
76+
var url = this.getUrl();
77+
return url.replace('&', '&');
7778
},
7879

7980

tests/AutolinkerSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,13 @@ describe( "Autolinker", function() {
744744
var result = autolinker.link( html );
745745
expect( result ).toBe('<p>Joe went to <a href="http://yahoo.com">yahoo.com</a>&nbsp;and <a href="http://google.com">google.com</a></p>');
746746
} );
747+
748+
it( "should handle &amp; inside a url and not ignore it", function() {
749+
var html = "<p>Joe went to example.com?arg=1&amp;arg=2</p>";
750+
751+
var result = autolinker.link( html );
752+
expect( result ).toBe('<p>Joe went to <a href="http://example.com?arg=1&arg=2">example.com?arg=1&amp;arg=2</a></p>');
753+
} );
747754

748755
} );
749756

0 commit comments

Comments
 (0)