This commit is contained in:
Joe
2026-01-16 15:49:34 +08:00
commit 550d3e1f42
380 changed files with 62024 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
package utils
import "html"
// EscapeString 转义 HTML 特殊字符,防止 XSS 攻击
// 将 < > & " ' 等字符转换为 HTML 实体
//
// 示例:
// EscapeString("<script>alert('XSS')</script>")
// 返回: "&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;"
func EscapeString(s string) string {
return html.EscapeString(s)
}
// EscapeBytes 转义字节数组中的 HTML 特殊字符
func EscapeBytes(b []byte) []byte {
return []byte(html.EscapeString(string(b)))
}