All escaping functions replace HTML reserved characters.

This commit is contained in:
Chad Weider 2012-01-14 14:46:15 -08:00
parent 30da7357e5
commit 6e36b59a59
4 changed files with 20 additions and 5 deletions

View file

@ -142,7 +142,14 @@ function binarySearchInfinite(expectedLength, func)
function htmlPrettyEscape(str)
{
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\r?\n/g, '\\n');
return str.replace(/[&"<>]/g, function (c) {
return {
'&': '&amp;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
}[c] || c;
}).replace(/\r?\n/g, '\\n');
}
if (typeof exports !== "undefined")