I am writing a Chrome extension that includes performing a lot of the following task: disinfection of strings that may contain HTML tags by converting < , > and & to < , > and & respectively.
(In other words, just like PHP htmlspecialchars(str, ENT_NOQUOTES) - I don't think there is a real need to convert double quote characters.)
This is the fastest function I've found so far:
function safe_tags(str) { return str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') ; }
But there is still a lot of backwardness when I need to run several thousand lines at a time.
Can anyone improve this? This is mainly for strings of 10 to 150 characters, if that matters.
(One of my ideas was not to worry about coding the sign more than the sign - was there any real danger?)
performance javascript string html regex
callum Mar 31 '11 at 11:28 2011-03-31 11:28
source share