Created
July 17, 2023 04:55
-
-
Save daformat/78f26d65bd51bbd44e9ddf03d0231d5e to your computer and use it in GitHub Desktop.
This file contains 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 str = "<svg onload=alert(1)>"; | |
const host = typeof document !== 'undefined' ? document.createElement("p") : undefined; | |
let converted | |
if (host) { | |
host.textContent = str; | |
converted = host.innerHTML; | |
} else { | |
converted = str.replaceAll('<', '<').replaceAll('>', '>') | |
} | |
console.log(converted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment