Skip to content

fix(discord): don't mangle email addresses into mentions#651

Merged
bensabic merged 2 commits into
vercel:mainfrom
Osamaali313:fix/discord-email-mentions
Jun 28, 2026
Merged

fix(discord): don't mangle email addresses into mentions#651
bensabic merged 2 commits into
vercel:mainfrom
Osamaali313:fix/discord-email-mentions

Conversation

@Osamaali313

Copy link
Copy Markdown
Contributor

Bug

The Discord adapter converts @mentions with /@(\w+)/g in two places — DiscordFormatConverter.convertMentionsToDiscord (plain/raw messages) and the text-node branch of nodeToDiscordMarkdown (markdown/AST messages):

text.replace(/@(\w+)/g, "<@$1>");

That pattern matches @word even when the @ is preceded by a word character, so it rewrites email addresses and word@word handles into broken mentions:

input before after
Contact me at user@example.com Contact me at user<@example>.com Contact me at user@example.com
ping support@vercel.com ping support<@vercel>.com ping support@vercel.com
hey @alice hey <@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.ts asserting Contact me at user@example.com round-trips through toAst/fromAst without becoming a mention. Includes a changeset (@chat-adapter/discord patch). Commit is signed (Verified) and DCO signed-off.

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>
@Osamaali313 Osamaali313 requested a review from a team as a code owner June 27, 2026 20:24
Copilot AI review requested due to automatic review settings June 27, 2026 20:24
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

@Osamaali313 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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 bensabic merged commit 490fa00 into vercel:main Jun 28, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants