refactor(shared): share the bare-mention scanner across Discord, Teams, and Slack#652
Open
bensabic wants to merge 1 commit into
Open
refactor(shared): share the bare-mention scanner across Discord, Teams, and Slack#652bensabic wants to merge 1 commit into
bensabic wants to merge 1 commit into
Conversation
…ord, teams, slack Introduce a context-aware bare-@mention resolver in @chat-adapter/shared (moved verbatim from the slack adapter) that skips code spans, URLs, schemeless hosts, and existing angle-bracket tokens before converting a bare @name via a platform-specific replacer. - shared: export replaceBareMentions + MentionReplacer; add direct tests - slack: source replaceBareMentions from @chat-adapter/shared (delete the local mentions.ts); behavior unchanged - discord: replace the /@(\w+)/g regex with the scanner in both conversion sites, fixing emails, @Handles in URLs, and code-span mentions being mangled into mentions and double-wrapping of existing <@id> tokens - teams: same fix (identical bug) for <at> mention tags Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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 Discord adapter (fixed in #651) converts bare
@mentionswith a regex. A single-character lookbehind can't tell whether an@sits inside a URL, a code span, or an email host, so it still mangles cases the regex can't see. The Slack adapter already had a robust character-scanning resolver —replaceBareMentions— that handles exactly those cases, but it lived insideadapter-slack.This lifts that scanner into
@chat-adapter/sharedand points every adapter that does bare-mention conversion at it: Slack (dedup, no behavior change), Discord, and Teams — which had the identical/@(\w+)/g→<at>$1</at>bug in two places.What changed
@chat-adapter/shared— newreplaceBareMentions(+MentionReplacertype), moved verbatim from Slack. It skips inline/fenced code, scheme + schemeless URLs, and existing<…>tokens before handing each real@nameto a platform-specific replacer. Adds a dedicated test file (the scanner had no direct tests before).replaceBareMentionsfrom@chat-adapter/shared; localmentions.tsdeleted. Behavior unchanged.<at>…</at>mention tags.What this fixes (Discord + Teams)
Across both the
{markdown}/AST and{raw}/plain-string paths:https://github.com/@vercelhttps://github.com/<@vercel>twitter.com/@jacktwitter.com/<@jack>`ping @here``ping <@here>`<@123>(Discord, raw)<<@123>>Emails (
user@example.com), period-prefixed mentions (docs.@everyone), and existing tokens keep working.Notes
.changeset/config.jsonusesfixed: [["chat", "@chat-adapter/*"]], so the@chat-adapter/sharedminor bump carries the whole family to a minor release; thediscord/teamspatchchangesets exist for their changelog text. Slack has no behavioral change, so it gets no changeset.discord-email-mentions.mdchangeset stays; this PR's scanner supersedes its regex implementation, so the two Discord changelog entries read as a progression.