From 513ed653e2752a4a06777b89c288e38d12a183f8 Mon Sep 17 00:00:00 2001 From: yaodeshun Date: Fri, 31 Oct 2025 14:38:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E4=BC=A0=E5=85=A5=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E5=B1=9E=E6=80=A7key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/gamelog/sdk.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/package/gamelog/sdk.go b/package/gamelog/sdk.go index fadc73f..20efa1b 100644 --- a/package/gamelog/sdk.go +++ b/package/gamelog/sdk.go @@ -72,6 +72,13 @@ var safePropertyRE = regexp.MustCompile(`[/"'\\\/]`) // 设置某些字段只允许包含字母、数字和下划线 var onlyWordRE = regexp.MustCompile(`\W`) +var nonWordCharRes = regexp.MustCompile(`[^\w]`) + +func hasNonWordChar(s string) bool { + // 匹配非 \w 字符的正则表达式 + return nonWordCharRes.MatchString(s) +} + var onlyWordPropertyNames = map[string]struct{}{ "nickname": {}, } @@ -83,7 +90,12 @@ func SetOnlyWordProperty(propertyNames ...string) { } func safeProperty(property map[string]any) { + delkeys := []string{} for k, v := range property { + if hasNonWordChar(k) { + delkeys = append(delkeys, k) + continue + } if _, ok := onlyWordPropertyNames[k]; ok { if _, ok := v.(string); ok { property[k] = onlyWordRE.ReplaceAllString(gconv.String(v), "*") @@ -93,6 +105,9 @@ func safeProperty(property map[string]any) { } } + for _, delkey := range delkeys { + delete(property, delkey) + } } func getLocationMapValue(key string) *time.Location {