Visitar URL original
fix: reject unbalanced parentheses in link destinations by giaBaoJS · Pull Request #4107 · markedjs/marked · GitHub
Skip to content

fix: reject unbalanced parentheses in link destinations - #4107

Merged
UziTech merged 1 commit into
markedjs:masterfrom
giaBaoJS:fix/def-unbalanced-parens
Oct 5, 2026
Merged

UziTech merged 1 commit into
markedjs:masterfrom
giaBaoJS:fix/def-unbalanced-parens

Conversation

@giaBaoJS

Copy link
Copy Markdown
Contributor

Marked version: 18.0.13

Markdown flavor: CommonMark

Description

marked.parse('[a]: /url(x\n') returns an empty string. The line disappears from the output. commonmark@0.31.2, the devDependency already in the repo, returns <p>[a]: /url(x</p>.

A bare link destination "includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses" (spec 0.31.2), and a link reference definition is defined in terms of that destination. So [a]: /url(x is not a definition and the line stays a paragraph. Tokenizer.def accepted it anyway and produced a def token, which renders nothing, so the source text was dropped.

Tokenizer.link has run this check since #3664. def never did.

Second half: findClosingBracket returned early when the string held no ), so an unmatched ( counted as balanced. That reaches inline links too, where [link](foo(bar) linked instead of staying literal. Both cases are in the fixtures, and every expected output there matches the reference parser byte for byte.

Conformance does not move: 649/652 with gfm off, 645/652 with gfm on, before and after, and the completion table is unchanged. The 652 hold no example of this shape, which is why it was never measured.

test:unit already fails on url email protocols at master 7f7a496, before this branch.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

@giaBaoJS 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 Sep 24, 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 Sep 25, 2026 2:47pm 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.

Rebase on master to get tests to pass

@giaBaoJS
giaBaoJS force-pushed the fix/def-unbalanced-parens branch from d6e7ede to e25be2b Compare September 25, 2026 08:52
@giaBaoJS

Copy link
Copy Markdown
Contributor Author

Rebased. Locally the unit suite is 192 passing where it was 191 with one failure before, and the spec suite is 1863 passing with both new fixtures running.

@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! 💯

@UziTech
UziTech merged commit 3363c99 into markedjs:master Oct 5, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 5, 2026
# [18.1.0](v18.0.14...v18.1.0) (2026-10-05)

### Bug Fixes

* avoid cubic backtracking on unicode whitespace in a link destination ([#4106](#4106)) ([0d20220](0d20220))
* load CLI configs with top-level await ([#4100](#4100)) ([c61543e](c61543e))
* reject unbalanced parentheses in link destinations ([#4107](#4107)) ([3363c99](3363c99))

### Features

* add linkParenPossible to lexer state to fail fast for link token generation ([#4070](#4070)) ([4ee44f7](4ee44f7))

This branch was successfully deployed

1 active deployment
Preview — e25be2b0 Deployed Sep 25, 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