Repository navigation
fix(ui): match hyphens and dots in mentions - #1655
Open
MaxFreedomPollard wants to merge 1 commit into
Open
MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
matchedUsers builds the mention_username_list sent with a new comment, but its pattern stops at "-" and ".", while parseUserInfo, which turns the same text into links, accepts both. A comment mentioning the user "jane-doe" links to /users/jane-doe, but the mention notification is looked up for "jane": another user receives it, or nobody does. Use the parseUserInfo pattern in matchedUsers so the users who are notified are the users the comment links to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Proposed Changes
When a comment mentions a user whose username contains
-or., the mention notification goes to the wrong account, or to nobody, although the link in the comment is right.handleSendReplybuilds the request from two helpers (ui/src/components/Comment/index.tsx:228-235):parseUserInfoturns@nameinto the link stored inoriginal_text, andmatchedUsersproducesmention_username_list, the usernames the backend notifies. They disagree on which characters a username may contain:Hyphenated usernames are the common case: sign-up derives the username from the display name by lowercasing it and replacing spaces with
-(internal/service/user_common/user.go:201-202), so "Jane Doe" becomesjane-doe, and the profile settings accepta-z,0-9and- . _. Pickingjane-doein the mention dropdown inserts@jane-doe(ui/src/components/Mentions/index.tsx:110), and the comment links to/users/jane-doe, butmention_username_listis["jane"]. The backend looks each name up exactly (internal/service/comment/comment_service.go:262,notificationMention), so a user namedjane, if there is one, gets a "mentioned you" notification for a comment that has nothing to do with them, andjane-doegets nothing. Since a non-empty mention list also skips the usual notification to the post's author, with nojanenobody is notified at all.Comments that go through review already get this right:
internal/service/review/review_service.go:472reads the usernames back from the stored links withconverter.GetMentionUsernameList, which yieldsjane-doe. Only the direct path uses the list from the UI.parseUserInfopattern inmatchedUsers, so the users who are notified are the users the comment links to, as in the review path|is no longer in the pattern: before, a comment containing@|madematchedUsersthrow aTypeError(the inner pattern found no match), so it could not be submittedA mention typed directly before a full stop (
thanks @alice.) was already linked to/users/alice.; its notification now follows the link, as the review path already does. Trimming trailing punctuation would change the links too, and usernames may end in., so that is left out of this fix.Testing
The UI has no test runner, so this adds no unit test. I loaded
ui/src/utils/common.tsfromdev(a570e3a) and from this branch in Node 22 with type stripping (node --experimental-strip-types, withi18next,diffand the two@/common/*imports stubbed), and comparedmatchedUsers(text)with the usernames in the linksparseUserInfo(text)produces:@jane-doe can you take a look?jane-doejanejane-doecc @john.smith and @sam_leejohn.smith,sam_leejohn,sam_leejohn.smith,sam_lee@alice thanksalicealicealicesee @|TypeErrorOver 20,000 random strings of up to 24 characters drawn from letters, digits,
- . _ @ | , ! ?, spaces and newlines, the two disagreed on 5,309 before (1,464 of them throwing) and on none after.tsc, ESLint and a run in the browser were not done here.🤖 Generated with Claude Code