Last active
May 7, 2020 01:42
-
-
Save ThaddeusJiang/ab9d4557ffb85a212b9005f46ace24de to your computer and use it in GitHub Desktop.
XSS 对应 escapeHtml.js
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
// XSS 对应 | |
function escapeHtml(value) { | |
if (typeof value !== 'string') { | |
return value | |
} | |
return value.replace(/[&<>`"'\/]/g, function(result) { | |
return { | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
'`': '`', | |
'"': '"', | |
"'": ''', | |
'/': '/', | |
}[result] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
拷贝下来,然后
escapeHtml(your_html_string)
。。。