From c40a90243df74e62f4aeb691cf8e7aa098fa61a3 Mon Sep 17 00:00:00 2001 From: renpengfei <244098063@qq.com> Date: Mon, 23 Feb 2026 16:51:10 +0800 Subject: [PATCH 1/2] 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 --- astrbot/core/config/astrbot_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/astrbot/core/config/astrbot_config.py b/astrbot/core/config/astrbot_config.py index bda02324e5..6a8a73c96e 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -52,6 +52,9 @@ def __init__( with open(config_path, encoding="utf-8-sig") as f: conf_str = f.read() + # Handle UTF-8 BOM if present + if conf_str.startswith('\ufeff'): + conf_str = conf_str[1:] conf = json.loads(conf_str) # 检查配置完整性,并插入 From cb510b4d66e6b1f78d9c07cfdf00bc283f9ab520 Mon Sep 17 00:00:00 2001 From: renpengfei <244098063@qq.com> Date: Mon, 23 Feb 2026 22:15:03 +0800 Subject: [PATCH 2/2] style: fix code formatting with ruff Fix single quote to double quote to comply with project code style. --- astrbot/core/config/astrbot_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/config/astrbot_config.py b/astrbot/core/config/astrbot_config.py index 6a8a73c96e..6a415e56c9 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -53,7 +53,7 @@ def __init__( with open(config_path, encoding="utf-8-sig") as f: conf_str = f.read() # Handle UTF-8 BOM if present - if conf_str.startswith('\ufeff'): + if conf_str.startswith("\ufeff"): conf_str = conf_str[1:] conf = json.loads(conf_str)