@pmun/utils / escapeHtml
Function: escapeHtml()
ts
function escapeHtml(html): string;
将字符串中的 HTML 特殊字符转义,防止 XSS 攻击
Parameters
html
string
包含 HTML 的字符串
Returns
string
转义后的安全字符串
Example
ts
escapeHtml('<div>Hello & World</div>') // '<div>Hello & World</div>'
escapeHtml('<script>alert("XSS")</script>') // '<script>alert("XSS")</script>'