Created
June 26, 2021 22:33
-
-
Save ruevaughn/db6a77f8e15a87b5e2e5f9580b532fb5 to your computer and use it in GitHub Desktop.
Input Sanitization Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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