Skip to content

fix(im): matrix mention boundary handles non-word localpart endings (#2749) - #2750

Merged
topcheer merged 1 commit into
mainfrom
fix/issue-2749
Sep 25, 2026
Merged

topcheer merged 1 commit into
mainfrom
fix/issue-2749

Conversation

@topcheer

Copy link
Copy Markdown
Owner

Fixes #2749

The #2719 word-boundary regex never matched when the localpart legally ends with a non-word character (Matrix charset [a-z0-9._=-+/] allows bot-, x=, a., u/): hasMention returned false (message silently dropped in requireMention rooms) and stripMention left the raw @bot- prefix in the LLM prompt.

Implementation note: the issue's suggested negative lookahead (?![a-z0-9._=\-+/]) (correctly excluding ALL legal continuation chars, per issue-fixer's amendment) does not compile - Go's RE2 has no (?!...). Implemented as an equivalent RE2-safe post-match boundary check: mentionsLocalPart / stripLocalPartMention match @localpart then verify the following byte is NOT a legal continuation character.

Semantics:

Tests: five issue endings (mention + strip), prefix-confusion refusals (al/alex, bot/bot.a, dev/dev+x), word-ending unchanged; im suite green 37s.

…2749)

The #2719 word-boundary regex never matched when the localpart legally
ends with a non-word character (Matrix charset [a-z0-9._=-+/] allows
'bot-', 'x=', 'a.', 'u/'): hasMention returned false - the message was
silently dropped in requireMention rooms - and stripMention left the
raw '@bot-' prefix in the LLM prompt.

The obvious fix (negative lookahead excluding legal continuation chars)
does not compile: Go's RE2 has no (?!...). Implemented as a post-match
boundary check instead - mentionsLocalPart / stripLocalPartMention match
'@localpart' and verify the following byte is NOT a legal localpart
continuation character. For word-ending localparts this is exactly the
old \b semantics; the #2719 prefix-confusion guarantee ('@bot' must not
match inside '@bot.a') is preserved.

Tests: the issue's five non-word endings (mention detected + prefix
stripped), prefix-confusion refusals (al/alex, bot/bot.a, dev/dev+x),
and word-ending behavior unchanged; im package suite green 37s.
@topcheer

Copy link
Copy Markdown
Owner Author

合并说明:techwriter_techwriter222_agent 代裁 approve(后验边界方案正确+RE2 等价+#2719 前缀拒配保持;附非阻塞发现:旧 regex (?i) 大小写不敏感而新实现 needle 未 ToLower——大写 localpart 自建 homeserver 漏配,fixer 建议一行补丁+大写用例,后续小 PR 补)。CI 全绿(wecom flake rerun 定性成立)。执行合并,#2749 随链关闭。

@topcheer
topcheer merged commit 822f975 into main Sep 25, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[code-review] matrix mention \\b 边界对以非 word 字符结尾的 localpart 失效:@bot- 等合法 Matrix 用户名被静默吞消息

1 participant