Skip to content

Commit

Permalink
Escape HTML uses &esamattis#39; instead of '
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Nov 2, 2012
1 parent 9df4736 commit 1f986aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/underscore.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
lt: '<',
gt: '>',
quot: '"',
apos: "'",
amp: '&'
amp: '&',
apos: "'"
};

var reversedEscapeChars = {};
for(var key in escapeChars){ reversedEscapeChars[escapeChars[key]] = key; }
for(var key in escapeChars) reversedEscapeChars[escapeChars[key]] = key;
reversedEscapeChars["'"] = '#39';

// sprintf() for JavaScript 0.7-beta1
// http://www.diveintojavascript.com/projects/javascript-sprintf
Expand Down
5 changes: 3 additions & 2 deletions test/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ $(document).ready(function() {

test('String: escapeHTML', function(){
equal(_('<div>Blah & "blah" & \'blah\'</div>').escapeHTML(),
'&lt;div&gt;Blah &amp; &quot;blah&quot; &amp; &apos;blah&apos;&lt;/div&gt;');
'&lt;div&gt;Blah &amp; &quot;blah&quot; &amp; &#39;blah&#39;&lt;/div&gt;');
equal(_('&lt;').escapeHTML(), '&amp;lt;');
equal(_(5).escapeHTML(), '5');
equal(_('').escapeHTML(), '');
Expand All @@ -371,9 +371,10 @@ $(document).ready(function() {
});

test('String: unescapeHTML', function(){
equal(_('&lt;div&gt;Blah &amp; &quot;blah&quot; &amp; &apos;blah&apos;&lt;/div&gt;').unescapeHTML(),
equal(_('&lt;div&gt;Blah &amp; &quot;blah&quot; &amp; &apos;blah&#39;&lt;/div&gt;').unescapeHTML(),
'<div>Blah & "blah" & \'blah\'</div>');
equal(_('&amp;lt;').unescapeHTML(), '&lt;');
equal(_('&apos;').unescapeHTML(), '\'');
equal(_('&#39;').unescapeHTML(), '\'');
equal(_('&#0039;').unescapeHTML(), '\'');
equal(_('&#x4a;').unescapeHTML(), 'J');
Expand Down

0 comments on commit 1f986aa

Please sign in to comment.