fix(discord): don't mangle email addresses into mentions#651
Merged
Conversation
convertMentionsToDiscord and the text-node branch of nodeToDiscordMarkdown used /@(\w+)/g, which matches an @ even when preceded by a word char, so emails and word@word handles were rewritten as broken mentions (e.g. user@example.com -> user<@example>.com). The Slack adapter already guards against this with a word-boundary check. Use a shared top-level BARE_MENTION_PATTERN with a negative lookbehind so only @ at a word boundary becomes a mention; emails are left intact and real bare mentions still convert. Adds a regression test. Signed-off-by: Osamaali313 <86572800+Osamaali313@users.noreply.github.com>
Contributor
|
@Osamaali313 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Refine the bare-mention lookbehind introduced in the previous commit: - exclude `<` so an already-formatted mention like `<@123>` in raw text is no longer re-wrapped into `<<@123>>` - drop the `.` exclusion: the `\w` word boundary already protects emails (`user@example.com`), and excluding `.` silently dropped legitimate mentions that follow a period (e.g. `docs.@everyone`) Add regression tests for the raw-path double-wrap and period-prefixed mention cases, and broaden the changeset wording. Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
bensabic
approved these changes
Jun 28, 2026
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.
Bug
The Discord adapter converts
@mentionswith/@(\w+)/gin two places —DiscordFormatConverter.convertMentionsToDiscord(plain/rawmessages) and the text-node branch ofnodeToDiscordMarkdown(markdown/AST messages):That pattern matches
@wordeven when the@is preceded by a word character, so it rewrites email addresses andword@wordhandles into broken mentions:Contact me at user@example.comContact me at user<@example>.comContact me at user@example.comping support@vercel.comping support<@vercel>.comping support@vercel.comhey @alicehey <@alice>hey <@alice>(unchanged)The Slack adapter already guards against exactly this with a word-boundary check (
replaceBareMentions); the Discord converter didn't.Fix
Introduce a shared top-level
BARE_MENTION_PATTERN = /(?<![\w@.])@(\w+)/g(per AGENTS.md, regex literals live at top level) with a negative lookbehind, so only an@at a word boundary becomes a mention. Emails/handles are left intact; real bare mentions still convert. Used in both conversion sites.Test
Adds a regression test in
markdown.test.tsassertingContact me at user@example.comround-trips throughtoAst/fromAstwithout becoming a mention. Includes a changeset (@chat-adapter/discordpatch). Commit is signed (Verified) and DCO signed-off.