Skip to content
Create a gist now

Instantly share code, notes, and snippets.

more efficient catch-all
var MAP = { '&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'};
function escapeHTML (s, forAttribute) {
return s.replace(forAttribute ? /[&<>'"]/g : /[&<>]/g, function(c) {
return MAP[c];
Chexpir commented Sep 28, 2015

This approach does not work for something such as

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.