fix(im): matrix mention boundary handles non-word localpart endings (#2749) - #2750
Merged
Merged
Conversation
…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.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2749
The #2719 word-boundary regex never matched when the localpart legally ends with a non-word character (Matrix charset
[a-z0-9._=-+/]allowsbot-,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/stripLocalPartMentionmatch@localpartthen verify the following byte is NOT a legal continuation character.Semantics:
@botdoes not match inside@bot.a(different user's localpart)Tests: five issue endings (mention + strip), prefix-confusion refusals (al/alex, bot/bot.a, dev/dev+x), word-ending unchanged; im suite green 37s.