Browse Source

fix: escape regex patterns when matching name

master
lanvent 1 year ago
parent
commit
361f599df0
2 changed files with 2 additions and 2 deletions
  1. +1
    -1
      channel/chat_channel.py
  2. +1
    -1
      channel/wechat/wechaty_message.py

+ 1
- 1
channel/chat_channel.py View File

@@ -115,7 +115,7 @@ class ChatChannel(Channel):
if not conf().get("group_at_off", False): if not conf().get("group_at_off", False):
flag = True flag = True
pattern = f"@{self.name}(\u2005|\u0020)" pattern = f"@{self.name}(\u2005|\u0020)"
content = re.sub(pattern, r"", content)
content = re.sub(re.escape(pattern), r"", content)


if not flag: if not flag:
if context["origin_ctype"] == ContextType.VOICE: if context["origin_ctype"] == ContextType.VOICE:


+ 1
- 1
channel/wechat/wechaty_message.py View File

@@ -87,7 +87,7 @@ class WechatyMessage(ChatMessage, aobject):
if not self.is_at: # 有时候复制粘贴的消息,不算做@,但是内容里面会有@xxx,这里做一下兼容 if not self.is_at: # 有时候复制粘贴的消息,不算做@,但是内容里面会有@xxx,这里做一下兼容
name = wechaty_msg.wechaty.user_self().name name = wechaty_msg.wechaty.user_self().name
pattern = f"@{name}(\u2005|\u0020)" pattern = f"@{name}(\u2005|\u0020)"
if re.search(pattern, self.content):
if re.search(re.escape(pattern), self.content):
logger.debug(f"wechaty message {self.msg_id} include at") logger.debug(f"wechaty message {self.msg_id} include at")
self.is_at = True self.is_at = True




Loading…
Cancel
Save