Support underscores in @ mention username regex#14849
Merged
Conversation
- Updated mention regex in resolve_mentions.cjs to allow underscores - Updated mention regex in sanitize_content_core.cjs to allow underscores - Updated mention regex in sanitize_content.cjs to allow underscores - Added comprehensive tests for usernames with underscores in resolve_mentions.test.cjs - Added tests for mention neutralization with underscores in sanitize_content.test.cjs - All 247 tests passing Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update escape function to allow underscores in @ mentions
Support underscores in @ mention username regex
Feb 10, 2026
pelikhan
approved these changes
Feb 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the @mention regex pattern across the JavaScript sanitization and mention resolution modules to support underscores in GitHub usernames, which are valid according to GitHub's username requirements. The regex pattern was previously limited to alphanumerics and hyphens, excluding underscores.
Changes:
- Updated the @mention regex pattern from
[A-Za-z0-9-]to[A-Za-z0-9_-]in three core modules - Added comprehensive test coverage for mentions with underscores in various combinations
- Maintained the constraint that usernames must start and end with alphanumeric characters
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/resolve_mentions.cjs | Updated mention extraction regex to include underscores in the character class |
| actions/setup/js/sanitize_content_core.cjs | Updated mention neutralization regex to include underscores in the character class |
| actions/setup/js/sanitize_content.cjs | Updated selective mention filtering regex to include underscores in the character class |
| actions/setup/js/resolve_mentions.test.cjs | Added 5 new test cases covering underscore handling in mentions, including edge cases |
| actions/setup/js/sanitize_content.test.cjs | Added 7 new test cases covering underscore handling in both neutralization and allowedAliases scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
The @ mention extraction regex only allowed alphanumerics and hyphens
[A-Za-z0-9-], excluding underscores. GitHub usernames support underscores.Changes
Updated regex pattern in 3 files:
resolve_mentions.cjs- mention extractionsanitize_content_core.cjs- neutralization of all mentionssanitize_content.cjs- selective mention filteringPattern change:
Usernames still must start and end with alphanumeric characters per GitHub's constraints.
Examples now handled:
@user_name→ extracted asuser_name@github_copilot→ extracted asgithub_copilot@my_org/my_team→ extracted asmy_org/my_team@user_→ extracted asuser(trailing underscore excluded)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.