Skip to content

fix: allow Unicode whitespace in URI autolinks - #4247

Open
hakarrr wants to merge 15 commits into
markedjs:masterfrom
hakarrr:fix/uri-autolink-unicode-whitespace
Open

hakarrr wants to merge 15 commits into
markedjs:masterfrom
hakarrr:fix/uri-autolink-unicode-whitespace

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Marked version: master (c6b22e89)

Markdown flavor: CommonMark, GFM and pedantic

Description

CommonMark 6.5 defines an angle URI autolink as a scheme and colon followed by characters other than ASCII controls, ASCII space and angle brackets. The current \s exclusion also rejects nonbreaking spaces and other Unicode whitespace that the rule allows.

Replace that broad whitespace exclusion with ASCII space. For example, an angle URI containing a literal NBSP now produces a link with the original label and a percent-encoded destination. Email and bare URL recognition are unchanged. The shared autolink rule intentionally changes pedantic mode too.

Validate masking candidates against the original source rather than escape placeholders. Otherwise, a backslash-escaped closing angle can make the mask extend past the real autolink and hide an emphasis closer. This support fix is included here independently of the same original-byte validation in unmerged #4242; this PR does not require #4242.

Demo: master / CommonMark.

Tests

  • One exact-output GFM fixture covers Unicode whitespace in angle URIs, emphasis, blockquotes, link/image labels, invalid ASCII whitespace, invalid schemes, nested angles, email controls and escaped-angle masking regressions. The CommonMark and pedantic fixture copies were removed in review, since only GFM is affected by autolink.
  • API tests check link text, destination and autolink metadata for ten Unicode separators in GFM mode, plus ASCII space/control rejection in GFM mode.
  • npm test: 2,037 spec tests and 258 unit tests pass, plus UMD, CJS, types and lint. npm run build:reset and git diff --check pass.
  • Structured matrix: 194,208 modern parses, 44,600 changed outputs, 42,320 new normalized cmark matches, zero prior-match regressions and 2,280 remaining mismatches. There are 22,300 changes in the corresponding 97,104 pedantic parses.
  • Seeded generated checks: 120,000 parses, 767 changes, 639 new normalized cmark matches, zero prior-match regressions and 128 remaining mismatches. A separate 40,000-case sample has 270 pedantic changes.
  • Escape/masking checks: 12,250 parses, 560 changes, 304 new normalized cmark matches, zero prior-match regressions and 256 remaining mismatches. Another 100,000 emphasis/link/image stress parses have 82,689 changes, 67,145 new normalized matches, zero regressions and 15,544 remaining mismatches.

These are bounded probes, not full conformance claims. Comparison normalization decodes HTML entities and collapses whitespace. Existing unrelated Unicode line-separator emphasis behavior is not fixed here. The exact fixtures retain Marked's existing image-tag style and pedantic tab expansion.

Contributor

  • Tests exist to ensure functionality and minimize regression.
  • No tests required for this PR.
  • If submitting a new feature, it has been documented in the appropriate places.

Committer

  • CI is green (no forced merge required).
  • Squash and Merge PR following conventional commit guidelines.

hakarrr and others added 9 commits November 17, 2026 15:39
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@hakarrr 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 Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
marked-website Ready Ready Preview Dec 5, 2026 3:11am UTC

Request Review

@UziTech UziTech left a comment

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.

Let's just keep the GFM tests since that is all that are affected by autolink

hakarrr and others added 5 commits November 24, 2026 22:30
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, done. I removed the CommonMark and pedantic fixture pairs and kept only the GFM fixture, which is unchanged. The URI autolink unit tests now run in GFM mode only, with the same ten Unicode separators and eight ASCII space/control inputs. Production code is unchanged. Locally the full suite passes with 2,037 specs and 258 unit tests, down from 2,041 specs because of the four deleted fixtures. I also updated the PR description to match.

Comment thread test/unit/marked.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.

please use new spec tests instead of unit tests

The uri_autolink_unicode_whitespace_gfm spec fixture already covers the
Unicode whitespace cases and the ASCII space and control character
rejections, so the unit tests only repeat it.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I dropped the unit tests in 239c8cf. The GFM spec fixture is now the only test for this change.

@UziTech UziTech left a comment

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.

Thanks! 💯

This branch was successfully deployed

1 active (outdated) deployment
Preview — 239c8cf5 Deployed Dec 5, 2026 by vercel[bot]
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