Skip to content

Instantly share code, notes, and snippets.

@ruevaughn
Created June 26, 2021 22:33
Show Gist options
  • Save ruevaughn/db6a77f8e15a87b5e2e5f9580b532fb5 to your computer and use it in GitHub Desktop.
Save ruevaughn/db6a77f8e15a87b5e2e5f9580b532fb5 to your computer and use it in GitHub Desktop.
Input Sanitization Snippets
const unsafeCharacters = ["&", "`", "\"", "{", "}", "(", ")", "[", "]", "=", ",", "+"];
function sanitize(str) {
str += "";
for (let char of unsafeCharacters) {
str = str.replaceAll(char, `&#x${char.codePointAt().toString(0x10)};`);
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment