Skip to content

fix: fix infinite loop for indented code blank line#3947

Merged
UziTech merged 4 commits intomarkedjs:masterfrom
UziTech:code-blank-line
Apr 18, 2026
Merged

fix: fix infinite loop for indented code blank line#3947
UziTech merged 4 commits intomarkedjs:masterfrom
UziTech:code-blank-line

Conversation

@UziTech
Copy link
Copy Markdown
Member

@UziTech UziTech commented Apr 18, 2026

Marked version: v18.0.1

Description

Fix infinite loop in indented code with only whitespace.

In v18 we introduced a change to indented code that removes trailing blank lines, but the way we detect blank lines as any whitespace we can create empty token if the code is only whitespace (e.g. '\v' vertical tab). Currently we will just keep creating empty indented code tokens until we run out of memory.

Thanks for finding this @MaanVader

This PR checks for infinite loops and throws an error if found. It also defines a blank line in indented code tokens as only containing space or tab like it should. If the indented code block only has tabs or spaces it is not an indented code block according to CommonMark.

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
Copy link
Copy Markdown

vercel Bot commented Apr 18, 2026

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

A member of the Team first needs to authorize it.

@UziTech UziTech requested review from calculuschild and styfle April 18, 2026 04:04
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 18, 2026

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

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Apr 18, 2026 5:49am

Request Review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces infinite loop detection in the Lexer by monitoring the length of the source string during iteration. It also refactors error handling for infinite loops into a dedicated private method. Additionally, the trimTrailingBlankLines helper was updated to use a regex test for blank lines, and a new ReDoS test case was added. I have no feedback to provide.

@UziTech UziTech merged commit 58a52e8 into markedjs:master Apr 18, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Apr 18, 2026
## [18.0.2](v18.0.1...v18.0.2) (2026-04-18)

### Bug Fixes

* fix infinite loop for indented code blank line ([#3947](#3947)) ([58a52e8](58a52e8))
Logiclayer1111 pushed a commit to Logiclayer1111/marked that referenced this pull request Apr 20, 2026
## [18.0.2](markedjs/marked@v18.0.1...v18.0.2) (2026-04-18)

### Bug Fixes

* fix infinite loop for indented code blank line ([#3947](markedjs/marked#3947)) ([f2b378c](markedjs/marked@f2b378c))
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