fix: make user mentions case-insensitive
What was fixed
Closes #13374
Mentions now work even when the typed username uses different casing.
Before this change, if a user’s username was foo, typing @Foo or @FOO would not create a proper mention. This was inconsistent because Rocket.Chat already treats usernames as case-insensitive in other places, like user creation.
What changed
Updated the message save logic so user mentions are resolved case-insensitively.
Also updated the mention rendering logic so a differently-cased typed mention still gets highlighted correctly and uses the actual stored username.
Tests added
Added tests for:
- resolving a mixed-case typed mention to the correct existing user
- rendering a mixed-case mention as a normal highlighted mention
Summary by CodeRabbit
- Bug Fixes
- User mention matching is now case-insensitive, allowing mentions with any capitalization (e.g.,
@Rocket.Catcorrectly resolves to@rocket.cat). Mention links now use normalized usernames for consistency while preserving display names.
- User mention matching is now case-insensitive, allowing mentions with any capitalization (e.g.,
Looks like this PR is not ready to merge, because of the following issues:
- This PR is missing the 'stat: QA assured' label
- This PR is missing the required milestone or project
Please fix the issues and try again
If you have any trouble, please check the PR guidelines
⚠️ No Changeset found
Latest commit: 7fd925a00fb6b329971862e715e204efad7435ac
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.
Walkthrough
Fixes case-insensitive username mention resolution on both the client and server. MentionsParser.filterUser now uses toLowerCase for matching, and userTemplate receives the canonical username from the resolved user object. BeforeSaveMentions.getUsers switches to a findByUsernamesIgnoringCase DB query. Tests are added for both paths.
Changes
Case-insensitive user mention resolution
| Layer / File(s) | Summary |
|---|---|
Case-insensitive matching and canonical username rendering apps/meteor/app/mentions/lib/MentionsParser.ts, apps/meteor/server/services/messages/hooks/BeforeSaveMentions.ts |
filterUser compares usernames via toLowerCase instead of exact match. userTemplate is passed mentionObj?.username || mention as the canonical mention value and title. getUsers replaces the Mongo $in query with Users.findByUsernamesIgnoringCase. |
Unit tests for case-insensitive resolution apps/meteor/tests/unit/app/mentions/client.tests.js, apps/meteor/tests/unit/app/mentions/server.tests.js |
Client tests assert @Rocket.Cat renders with rocket.cat in link attributes for both default and RealNames modes. Server mock updated to use toLowerCase filtering; new test verifies @Rocket.Cat resolves to the rocket.cat user record. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested labels
type: bug
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Linked Issues check | ✅ Passed | The changes meet all coding requirements from issue #13374: case-insensitive mention matching [#13374], case-insensitive user retrieval [#13374], and proper mention rendering with normalized usernames [#13374]. |
| Out of Scope Changes check | ✅ Passed | All changes are directly scoped to the case-insensitive mention handling requirements; no unrelated modifications or refactoring beyond the stated objectives. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Title check | ✅ Passed | The title 'fix: make user mentions case-insensitive' directly and clearly describes the main objective of the PR - implementing case-insensitive user mention handling across the system. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
i have fix the issue related to casing please merge this pr