Repository navigation
fix: stop an unclosed inline raw tag from unescaping later blocks - #4130
Open
thebriangao wants to merge 1 commit into
Open
thebriangao wants to merge 1 commit into
thebriangao wants to merge 1 commit into
Conversation
An inline <pre>, <code>, <kbd> or <script> tag sets lexer.state.inRawBlock, which makes inlineText emit text without escaping it. The flag was never reset between blocks, so one unclosed tag left the text of every later paragraph, heading, list item and table cell unescaped: `i<n & m` came out as `i<n & m` instead of `i<n & m`, and a browser then parses the `<n` as an element and drops the text after it. Reset the flag before each block's inline run. Raw text within a block is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@thebriangao is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Marked version:
master(6a57018, 18.1.0)Markdown flavor: CommonMark|GitHub Flavored Markdown
Description
I couldn't find an existing issue for this.
An inline
<pre>,<code>,<kbd>or<script>tag setslexer.state.inRawBlock, which makesinlineTextemit text without escaping it. Nothing resets the flag between blocks. One unclosed tag therefore turns off escaping for every later block in the document: paragraphs, headings, list items and table cells.Expectation
Wrap the shortcut in a <kbd> tag. Then loop while i<n and stop. Done & dusted.This is what the
commonmarkandmarkdown-itdev-dependencies both produce.Result
In a browser the second paragraph renders as just "Then loop while i". The unescaped
<n and stop.</pis parsed as an element, and the rest of the line disappears. This matters for apps that render LLM/agent output with marked, which I do (with DOMPurify afterwards), because that prose often names a tag without backticks.Fix
Reset
inRawBlockbefore each block's inline run inLexer.lex(). Raw text within a block is unchanged, for example<code>a & b</code>, including when it spans a line break. The new spec covers both cases. This follows the same approach as theouterInRawBlockrestore in #4051, which fixed this leak for discarded link text.Verification
test/specs/new/unclosed_inline_raw_tagusesrenderExact, because the differ normalizes entities. It fails onmasterand passes with the fix.npm testpasses in full.new/originalspecs,docs/, and 20k fuzzed documents, each under 4 option sets.pedantic: true. It is a<script>spanning a blank line, which marked already splits with</p>\n<p>. Its second paragraph is now escaped as well.inLinkhas the same problem: an unclosed<a …>stops autolinking in later blocks. Its effect is milder, so I left it out to keep this PR focused. I'm happy to add it if you'd like.AI disclosure: the bug was found, and this fix and its verification were prepared, with Claude Code (AI-assisted).
Contributor
Committer
In most cases, this should be a different person than the contributor.
🤖 Generated with Claude Code