← Back to Pull requests

fix: preserve Unicode whitespace in inline link destinations #4249

Merged
hakarrr merged 5 files (316 lines) on Nov 27, 2026 22:18 UTC
View on GitHub
hakarrr hakarrr commented on Nov 17, 2026 10:38 UTC
Author

Marked version: master (c6b22e89)

Markdown flavor: CommonMark / GFM

Description

Non-ASCII whitespace at either end of an unbracketed inline link destination is removed. For example, when the spaces below are U+00A0, [x]( /url ) currently links to /url rather than %C2%A0/url%C2%A0. Images lose those destination characters too. The same characters already survive inside angle-bracket destinations.

Marked master demo / CommonMark demo

The modern link regex already separates ASCII space, tab and newline gaps from the captured destination. The final href.trim() then removes characters that belong to that destination. This change keeps that trim in pedantic mode only. It leaves the regex, angle validation, title handling and parenthesis consumption unchanged. The destination definition in CommonMark 0.31.2 excludes ASCII controls and space, not all Unicode whitespace.

This follows the destination/gap distinction in merged #4106. Open #4237 changes raw-token length calculation when a destination has extra closing parentheses; this PR does not change that calculation or resolve its cases.

Committed default-GFM fixtures assert exact rendered output for eight non-ASCII whitespace characters at the leading edge, trailing edge and both edges, for links and images. ASCII gaps, angle destinations and titles remain rendering controls, with a separate pedantic fixture checking unchanged trimming. CommonMark and GFM behavior was separately validated locally; identical mode copies are not committed. The lexer href/raw identity tests were removed at review, not replaced with equivalent API coverage.

Validation

  • npm test: passed, including 2,039 spec entries, 256 unit tests, UMD, CJS, types and lint.

  • npm run build:reset: passed afterward.

  • A structured local comparison covered 18,816 documents in both modern modes. All 11,776 changed outputs newly matched normalized cmark/cmark-gfm output; no prior matches regressed. All 18,816 pedantic controls were unchanged.

  • A seeded 150,000-document link corpus had 10,581 changed outputs: 10,387 new normalized reference matches, no prior-match regressions and 194 remaining mismatches. A separate 100,000-document escaped-label/code/HTML corpus had 56,389 changes: 55,841 new normalized matches, no prior-match regressions and 548 remaining mismatches. Another 40,000 pedantic controls were unchanged.
  • Those local comparisons decode entities and collapse whitespace, so they are not full conformance checks. The exact fixtures protect the encoded destination bytes in rendered links and images. At the maintainer's request, paired Markdown/HTML fixtures replace generated cases and unit tests; raw token identity assertions were removed. ASCII-gap, title, angle-destination and pedantic controls remain as fixtures. Existing malformed-angle, entity and parenthesis-consumption gaps remain outside this change.

    Contributor

  • Tests exist to ensure functionality and minimize regression.

  • 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.
  • Revision validation: no production source changes in the fixture migration. Hosted CI for the revision is not yet verified. AI assistance was used; the change and local results were independently reviewed before publication.

    The committed fixtures avoid duplicate mode copies where these cases use shared grammar. Both modern modes were also checked locally before deduplication.

    Diff: 316 lines (+315 / -1) across 5 files Reviewer: UziTech Review duration: 15099m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.43) × (1 − Review Confidence (0.72)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 316 lines diff across 5 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.48 · 4 substantive comment(s)
    0.48
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    72%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Real PR Conversation Timeline
    8 items
    vercel[bot] vercel[bot] commented on Nov 17, 2026 10:38 UTC
    Bot

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

    A member of the Team first needs to authorize it.

    vercel[bot] vercel[bot] commented on Nov 17, 2026 14:54 UTC
    Bot

    [vc]: #qBDfuIlWFMn6gi7SDUZepzo3+ZrKX5yUUlN7SjJWwUY=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJtYXJrZWQtd2Vic2l0ZSIsInByb2plY3RJZCI6InByal9RbnhOam0wSDI0YlVHQWI1MWIxUnVaa25ReXlZIiwidjAiOmZhbHNlLCJyb290RGlyZWN0b3J5IjpudWxsLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vbWFya2VkanMvbWFya2VkLXdlYnNpdGUvOHN3a1BGSGtKbndNRnRDbjVpNmFLRHpQaUM4ZyIsInByZXZpZXdVcmwiOiJtYXJrZWQtd2Vic2l0ZS1naXQtZm9yay1oYWthcnJyLWZpeC1pbmxpbmUtbGluay1mMjVhM2MtbWFya2VkanMudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsImxpdmVGZWVkYmFjayI6eyJyZXNvbHZlZCI6MCwidW5yZXNvbHZlZCI6MCwidG90YWwiOjAsImxpbmsiOiJtYXJrZWQtd2Vic2l0ZS1naXQtZm9yay1oYWthcnJyLWZpeC1pbmxpbmUtbGluay1mMjVhM2MtbWFya2VkanMudmVyY2VsLmFwcCJ9fV0sInJlcXVlc3RSZXZpZXdVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vdmVyY2VsLWFnZW50L3JlcXVlc3QtcmV2aWV3P293bmVyPW1hcmtlZGpzJnJlcG89bWFya2VkJnByPTQyNDkifQ==
    The latest updates on your projects. Learn more about Vercel for GitHub.

    | Project | Deployment | Actions | Updated |
    | :--- | :----- | :------ | :------ |
    | <a href="https://vercel.com/markedjs/marked-website"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_QnxNjm0H24bUGAb51b1RuZknQyyY&teamId=team_RpARALaqy6bNW7b6MI363ieY&s=32" width="16" height="16" align="middle" alt="" /></sup></a> marked-website | !Ready Ready | Preview | <relative-time datetime="2026-11-25T15:53:06.342Z">Nov 25, 2026 3:53pm UTC</relative-time> |

    <a href="https://vercel.com/vercel-agent/request-review?owner=markedjs&repo=marked&pr=4249" rel="noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://agents-vade-review.vercel.sh/request-review-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://agents-vade-review.vercel.sh/request-review-light.svg"><img src="https://agents-vade-review.vercel.sh/request-review-light.svg" alt="Request Review"></picture></a>

    UziTech UziTech requested changes on Nov 18, 2026 07:43 UTC
    Changes Requested Reviewer

    Use .md & .html files for tests in test/specs/new and remove unit tests

    UziTech UziTech commented on Nov 21, 2026 07:40 UTC
    Contributor

    One of the tests is different than commonmark. We should fix it or remove it from the tests.

    [x]( 	/url 	)
    

    This PR&options=%7B%0A%20%22async%22%3A%20false%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22extensions%22%3A%20null%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22hooks%22%3A%20null%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22tokenizer%22%3A%20null%2C%0A%20%22walkTokens%22%3A%20null%0A%7D&version=master)
    CommonMark&options=%7B%0A%20%22async%22%3A%20false%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22extensions%22%3A%20null%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22hooks%22%3A%20null%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22tokenizer%22%3A%20null%2C%0A%20%22walkTokens%22%3A%20null%0A%7D&version=commonmark)

    hakarrr hakarrr commented on Nov 24, 2026 16:41 UTC
    Author

    Removed the ASCII-tab case you identified and its expected output in 3941e8c and 52eefe9. The Unicode destination cases are unchanged, and there are no production changes in this revision. The separate ASCII-tab parser mismatch is not fixed by this PR.

    The published fixture files match the locally tested revision: npm test passed with 2,039 specs and 256 unit tests, followed by npm run build:reset. These are local results, not a claim that hosted CI is green.

    UziTech UziTech approved these changes on Nov 27, 2026 19:31 UTC
    Approved Reviewer

    Thanks! 💯

    styfle styfle approved these changes on Nov 27, 2026 20:31 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    hakarrr hakarrr
    Labels
    risk: low confidence: 72.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.3% (MEDIUM) · Higher = larger blast radius
    43.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.5% · Lower = rushed or shallow review
    72.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 11.9% · Safe to merge
    11.9%