fix: 修复 Cross-Review 发现的问题
This commit is contained in:
@@ -29,7 +29,15 @@ def cmd_record_event(args):
|
||||
for item in args.metadata:
|
||||
if '=' in item:
|
||||
key, value = item.split('=', 1)
|
||||
# 白名单校验:只允许字母、数字、下划线、连字符、点、空格
|
||||
import re
|
||||
if not re.match(r'^[\w\-\. \u4e00-\u9fff]+$', value):
|
||||
print(f"⚠️ 警告: metadata 值 '{value}' 包含不允许的字符,将被转义", file=sys.stderr)
|
||||
# 转义特殊字符,只保留安全字符
|
||||
value = re.sub(r'[^\w\-\. \u4e00-\u9fff]', '_', value)
|
||||
metadata[key] = value
|
||||
else:
|
||||
print(f"⚠️ 警告: 无效的 metadata 格式 '{item}',应为 key=value 格式,已忽略", file=sys.stderr)
|
||||
|
||||
# 记录事件
|
||||
record_event(
|
||||
|
||||
Reference in New Issue
Block a user