Handle invalid UTF-8 with replacement decoding

This commit is contained in:
jxxghp
2026-06-21 09:56:34 +08:00
parent 99e369aaa4
commit 68f18db374
29 changed files with 139 additions and 121 deletions
+2 -2
View File
@@ -44,7 +44,7 @@ class CategoryHelper(metaclass=WeakSingleton):
try:
if not self._category_path.exists():
shutil.copy(settings.INNER_CONFIG_PATH / "category.yaml", self._category_path)
with open(self._category_path, mode='r', encoding='utf-8') as f:
with open(self._category_path, mode='r', encoding='utf-8', errors='replace') as f:
try:
yaml_loader = ruamel.yaml.YAML()
self._categorys = yaml_loader.load(f)
@@ -67,7 +67,7 @@ class CategoryHelper(metaclass=WeakSingleton):
if not self._category_path.exists():
return config
try:
with open(self._category_path, 'r', encoding='utf-8') as f:
with open(self._category_path, 'r', encoding='utf-8', errors='replace') as f:
yaml_loader = ruamel.yaml.YAML()
data = yaml_loader.load(f)
if data: