Fixes Issue #350 -- Making _.escape dumber to allow double-escaping of HTML entities.

This commit is contained in:
Jeremy Ashkenas
2011-10-31 12:31:02 -04:00
parent 64b69c0cfa
commit ba96d168ec
2 changed files with 6 additions and 1 deletions

View File

@@ -41,6 +41,11 @@ $(document).ready(function() {
equals(_('champ').myReverse(), 'pmahc', 'mixed in a function to the OOP wrapper');
});
test("utility: _.escape", function() {
equals(_.escape("Curly & Moe"), "Curly & Moe");
equals(_.escape("Curly & Moe"), "Curly & Moe");
});
test("utility: template", function() {
var basicTemplate = _.template("<%= thing %> is gettin' on my noives!");
var result = basicTemplate({thing : 'This'});

View File

@@ -849,7 +849,7 @@
// Escape a string for HTML interpolation.
_.escape = function(string) {
return (''+string).replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
return (''+string).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
};
// Add your own custom functions to the Underscore object, ensuring that