Skip to content

fix: reject GFM email autolink when the domain ends in _ or - - #4063

Open
contactjawad wants to merge 1 commit into
markedjs:masterfrom
contactjawad:fix-gfm-email-autolink-trailing
Open

fix: reject GFM email autolink when the domain ends in _ or -#4063
contactjawad wants to merge 1 commit into
markedjs:masterfrom
contactjawad:fix-gfm-email-autolink-trailing

Conversation

@contactjawad

Copy link
Copy Markdown

The GFM email autolink rule mangles an address when its domain is immediately followed by _ or -.

The email sub-pattern in the GFM inline url rule ends with a (?![-_]) lookahead. Since that only forbids -/_ after the final domain character, the regex backtracks and gives that character back to satisfy the lookahead — truncating the last domain label and producing a wrong mailto: target plus a visibly split word (e.g. foo@bar.com- autolinks foo@bar.co and leaves m- behind).

Per the GFM spec a domain label must not end in _ or -. Changing the lookahead to (?![\w-]) also forbids a following word character, forcing the final label to match maximally; when the maximal domain is then followed by _/-, the whole autolink fails and the text is rendered as-is — which is the correct behaviour.

Added a unit test covering foo@bar.com_ and foo@bar.com-, both of which now tokenize as plain text. It fails on master and passes with this change.

The GFM inline url rule's email pattern used a trailing `(?![-_])` lookahead,
which let the regex give back the final domain character when the domain was
followed by `_` or `-`, truncating the last label and producing a wrong
`mailto:` target. Per the GFM spec a domain must not end in `_`/`-`; use a
`(?![\w-])` lookahead so the domain matches maximally and the autolink fails
cleanly (rendered as plain text) in that case.
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview Aug 23, 2026 12:43am

Request Review

Comment thread test/unit/Lexer.test.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you remove this test and add a test in https://github.com/markedjs/marked/tree/master/test/specs/new?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants