Skip to content

Detect emails followed by a hyphen - #128

Closed
dyk1454683243-sudo wants to merge 1 commit into
markdown-it:masterfrom
dyk1454683243-sudo:cursor/email-trailing-hyphen-43cc
Closed

dyk1454683243-sudo wants to merge 1 commit into
markdown-it:masterfrom
dyk1454683243-sudo:cursor/email-trailing-hyphen-43cc

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Fixes #93

test() treats a comma after a valid email as punctuation, but a hyphen makes the whole match fail:

const linkify = new LinkifyIt()
linkify.test('name@example.com')   // true
linkify.test('name@example.com,')  // true
linkify.test('name@example.com-')  // false  (before this change)

After:

linkify.test('name@example.com-')                 // true
linkify.match('name@example.com-')[0].text        // 'name@example.com'

Why

- is in Unicode {P}, so the host terminator's first lookahead accepts it. The second lookahead then rejects every hyphen:

(?=$|separators|{ZPCc})(?!-|_…)

That rejection is useful for URL hosts (google.com-based should not become a link). It is the wrong rule for emails: after a completed mail host the hyphen cannot continue the address (domain labels already consume internal hyphens, and emails have no path). So name@example.com- and mid-text cases like Contact name@example.com- for details are missed entirely.

Change

Mail hosts use a slightly looser terminator: - and -- are treated like other punctuation. --- stays opt-in ({ '---': true }), so the existing user@example.com---foo default-null behavior is unchanged.

URL host termination is left as-is.

Tests

  • Issue repro in test/api.test.mjs
  • Fixtures in test/fixtures/links.txt: trailing - / --, mid-text, mailto:, hyphenated domains (user@my-company.com)

A hyphen is Unicode punctuation, so it looks like a host terminator,
but get_host_terminator() rejects it to avoid compounds such as
google.com-based. After a completed email host that hyphen cannot
continue the address, so treat - / -- like a comma. --- stays opt-in.

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
@puzrin

puzrin commented Sep 20, 2026

Copy link
Copy Markdown
Member

@puzrin puzrin closed this Sep 20, 2026
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.

Email links followed by a hyphen are not detected

3 participants