From 040a182e716dd056ce2a7e698a54f4dca8d2444a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 17 Oct 2026 00:41:55 +0800 Subject: [PATCH] refactor(types): preserve parsed WeChat XML root guarantee --- app/modules/wechat/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/modules/wechat/__init__.py b/app/modules/wechat/__init__.py index dadf87616..28bc386cb 100644 --- a/app/modules/wechat/__init__.py +++ b/app/modules/wechat/__init__.py @@ -1,7 +1,7 @@ import json import re import xml.dom.minidom -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union, cast from urllib.parse import quote from app.adapters.external.wechat import WXBizMsgCrypt @@ -163,7 +163,8 @@ class WechatModule(_MessageChannelModuleBase[WeChat]): """ dom_tree = xml.dom.minidom.parseString(sMsg.decode('UTF-8')) - root_node = dom_tree.documentElement + # parseString 成功即有根元素;空文档会在解析阶段抛错。 + root_node = cast(xml.dom.minidom.Element, dom_tree.documentElement) # 消息类型 msg_type = DomUtils.tag_value(root_node, "MsgType") # Event event事件只有click才有效,enter_agent无效