fix(material): _normalize_scene 去除所有 Unicode 空白字符

之前只处理了半角空格和全角空格,换行、tab 等字符会导致
scene 与三级分类 name 匹配失败。改用 re.sub(r'\s+', '', scene)
统一清理所有 Unicode 空白字符。
This commit is contained in:
小鱼开发
2026-05-15 17:40:41 +08:00
parent 065bb4f66b
commit 60b4178cff
+3 -2
View File
@@ -8,6 +8,7 @@
import logging
import math
import random
import re
from sqlalchemy.ext.asyncio import AsyncSession
@@ -23,8 +24,8 @@ _USED_MATERIALS_TTL = 7 * 24 * 3600
def _normalize_scene(scene: str) -> str:
"""标准化场景描述,用于匹配三级分类 name"""
# 去除空格全角空格
return scene.replace(" ", "").replace("\u3000", "").strip()
# 去除所有 Unicode 空白字符(空格全角空格、换行、tab 等)
return re.sub(r"\s+", "", scene)
def _weighted_choice(materials: list) -> object: # noqa: ANN001