Skip to content

fix: an unmatched strong run before emphasis stays literal - #4008

Merged
UziTech merged 1 commit into
markedjs:masterfrom
spokodev:w33/marked-unclosed-strong-orphan
Aug 4, 2026
Merged

fix: an unmatched strong run before emphasis stays literal#4008
UziTech merged 1 commit into
markedjs:masterfrom
spokodev:w33/marked-unclosed-strong-orphan

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The input **a*b*c produced malformed output.

  • marked: <p>*<em>a</em>b*c</p>
  • CommonMark 0.31.2 reference and markdown-it: <p>**a<em>b</em>c</p>

When the ** opener finds no closer, the lexer reprocesses from the second *
of the run. That mid-run * greedily pairs with the * before b, even though
that * is itself the opener of *b*. The unmatched ** should stay literal
while the inner *b* forms its own emphasis.

The fix marks an opener that is reprocessed from inside its own delimiter run
(prevChar equals the delimiter character) and stops it from closing against an
ambiguous delimiter that can also open, so that delimiter opens its own span
instead. This is distinct from the valid cases **foo*, ***foo** and
****foo*, which close against unambiguous right delimiters and are preserved.

All CommonMark and marked spec tests pass. Added a spec fixture for the case.

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

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

@vercel

vercel Bot commented Jul 2, 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, Comment Jul 2, 2026 3:46pm

Request Review

@UziTech

UziTech commented Jul 24, 2026

Copy link
Copy Markdown
Member

@styfle any objections with merging this?

@UziTech
UziTech merged commit e8544e6 into markedjs:master Aug 4, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 4, 2026
## [18.0.9](v18.0.8...v18.0.9) (2026-08-04)

### Bug Fixes

* an unmatched strong run before emphasis stays literal ([#4008](#4008)) ([e8544e6](e8544e6))
* Fix spurious deeper nesting in a blockquote continuation ([#4030](#4030)) ([452f1ed](452f1ed))
* pedantic **foo:** and **"word"** emphasis parsing ([#3999](#3999)) ([823093f](823093f))
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