When I send / POST data to the server, I need HTMLencode characters (corresponding), since disabling input validation by setting validationRequest = falseis not a good practice.
All solutions finally replace the characters in the string:
This is what I wrote.
function htmlEncode(str) {
str = str.replace(/\&/g, "&");
str = str.replace(/\</g, "<");
str = str.replace(/\>/g, ">");
str = str.replace(/ /g, " ");
return str;
}
But perhaps the regular expression can be replaced with something much faster (don't get me wrong - I love the regular expression).
Also, working with indexes + substrings seems wasteful.
What is the fastest way to do this?
source
share