Browse Source

Perf: optimized html escape helper

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
c45c345c6b
  1. 4
      lib/common/utils.js

4
lib/common/utils.js

@ -30,11 +30,15 @@ function assign(obj /*from1, from2, from3, ...*/) {
}
var ESCAPE_TEST_RE = /[<>"]/;
function escapeHtml(str) {
if (ESCAPE_TEST_RE.test(str)) {
if (str.indexOf('&') >= 0) { str = str.replace(/&/g, '&amp;'); }
if (str.indexOf('<') >= 0) { str = str.replace(/</g, '&lt;'); }
if (str.indexOf('>') >= 0) { str = str.replace(/>/g, '&gt;'); }
if (str.indexOf('"') >= 0) { str = str.replace(/"/g, '&quot;'); }
}
return str;
}

Loading…
Cancel
Save