Skip to content

Commit 351895a

Browse files
authored
fix: 处理配置文件中的 UTF-8 BOM 编码问题 (#5376)
* fix(config): handle UTF-8 BOM in configuration file loading Problem: On Windows, some text editors (like Notepad) automatically add UTF-8 BOM to JSON files when saving. This causes json.decoder.JSONDecodeError: "Unexpected UTF-8 BOM" and AstrBot fails to start when cmd_config.json contains BOM. Solution: Add defensive check to strip UTF-8 BOM (\ufeff) if present before parsing JSON configuration file. Impact: - Improves robustness and cross-platform compatibility - No breaking changes to existing functionality - Fixes startup failure when configuration file has UTF-8 BOM encoding Relates-to: Windows editor compatibility issues * style: fix code formatting with ruff Fix single quote to double quote to comply with project code style.
1 parent c1009ad commit 351895a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

astrbot/core/config/astrbot_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def __init__(
5252

5353
with open(config_path, encoding="utf-8-sig") as f:
5454
conf_str = f.read()
55+
# Handle UTF-8 BOM if present
56+
if conf_str.startswith("\ufeff"):
57+
conf_str = conf_str[1:]
5558
conf = json.loads(conf_str)
5659

5760
# 检查配置完整性,并插入

0 commit comments

Comments
 (0)