Skip to content

fix(im): mattermost mention boundary handles usernames ending in -/. (#4322) - #4324

Merged
topcheer merged 1 commit into
mainfrom
fix-4322-mention-boundary
Oct 19, 2026
Merged

topcheer merged 1 commit into
mainfrom
fix-4322-mention-boundary

Conversation

@topcheer

Copy link
Copy Markdown
Owner

Closes #4322

根因(独立复核坐实)

RE2 \b 为 ASCII 词边界:Mattermost 用户名字符集 ^[a-z0-9.-_]+ 允许尾随 -/.,两侧均非词字符时 \b 数学上不可能匹配 → hasMention 漏判静默 return(无日志),stripMention 不剥离。

修复(RE2 无 lookahead,用字符集负边界)

  • 两处正则 \b → (?:$|[^a-z0-9.\-_]):提及终止仅当下 一字符非用户名字符
  • stripMention 捕获边界字符并入替换串($1),不吞后续分隔符
  • al/@alex 防误匹配语义保留(e ∈ 字符集仍拒);mention-gate 丢弃路径补 debug.Log(可诊断性)
  • 已知保守面:bot=al 文本 @al. 句号紧随(新字符集视 . 为名延续)不命中——旧 \b 命中;句号紧随提及极罕见,Mattermost 语义下按更可能全名处理更安全

验证

  • 回归测试 7 例(尾-/尾./end-of-text 命中+al 对照+@Dev-extra 防误伤)+ strip 分隔符保留 3 例
  • internal/im 全包 80s ok + 全仓 build 绿

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] mattermost hasMention/stripMention 的 \b 词边界对以 -/. 结尾的 bot 用户名永不匹配,非 DM 频道提及被静默丢弃

1 participant