Skip to content

Instantly share code, notes, and snippets.

@raycmorgan
Created January 28, 2010 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raycmorgan/289042 to your computer and use it in GitHub Desktop.
Save raycmorgan/289042 to your computer and use it in GitHub Desktop.
function sanitize(string) {
return string.replace(/[&<>"]/g, escapeReplace);
}
function escapeReplace(char) {
switch (char) {
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case '"': return '&quot;';
default: return char;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment