From 351895ae664ae0deef4aa32e78e4ce9c71f98d70 Mon Sep 17 00:00:00 2001 From: tangsenfei <155090747+tangsenfei@users.noreply.github.com> Date: Mon, 23 Feb 2026 22:27:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=20UTF-8=20BOM=20=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=20(#5376)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- 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 bda02324e..6a415e56c 100644 --- a/astrbot/core/config/astrbot_config.py +++ b/astrbot/core/config/astrbot_config.py @@ -52,6 +52,9 @@ class AstrBotConfig(dict): 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) # 检查配置完整性,并插入