Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)

Aperta Adatta ai principianti
#4,304 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@O1sumitkumar ci sta già lavorando.

Dal 2/12/2026.

  • #4305 di @O1sumitkumar — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
markdown, typescript
Ambito
backend, compilers

Direzione di ricerca

Inizia in src/Lexer.ts, in Lexer.inlineTokens, e confronta i due inserimenti di token abbreviati con il modo in cui inlineText imposta il flag escaped nei blocchi non elaborati. Aggiungi test di regressione per gli esempi forniti di script e code, quindi esegui gli spec test pertinenti; il lavoro è completato quando il loro contenuto rimane non sottoposto a escape all’interno dei tag.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Marked version: 18.2.1 – 18.4.0 (also current master 002336a5). 18.2.0 is fine.

Describe the bug

Since 18.2.1, the content of inline raw HTML tags that marked keeps as-is (<script>, <code>, <pre>, <kbd>) gets HTML-escaped from the first _, * or ~ that has no closer. Everything before that character is left alone; everything after it is escaped.

We hit this with buttons that keep text in a <script type="template"> and copy it with innerText. Shell commands nearly always contain a _, so '1'" > was copied as &#39;1&#39;&quot; &gt;.

To Reproduce

marked.parse('Run <script>a_b = "1" > 2</script>')
marked.parse("Run <code>a_b '1' > x</code>")

18.2.0 (expected):

<p>Run <script>a_b = "1" > 2</script></p>
<p>Run <code>a_b '1' > x</code></p>

18.2.1 – 18.4.0 (actual):

<p>Run <script>a_b = &quot;1&quot; &gt; 2</script></p>
<p>Run <code>a_b &#39;1&#39; &gt; x</code></p>

Cause

git bisect between v18.2.0 and v18.2.1 points to 0b8b3b3 (#4196, "close residual O(n²) parse time on unmatched emphasis/strikethrough delimiter runs").

The new shortcut in Lexer.inlineTokens that consumes a closer-less */_/~ run pushes a text token with escaped: false, ignoring this.state.inRawBlock. inlineText sets escaped from inRawBlock, so before #4196 the whole span stayed raw. Now the rest of the raw text is merged into that new, unescaped token, and the renderer escapes it.

Possible fix

Use the raw-block state in both places the shortcut pushes a token (src/Lexer.ts):

-            tokens.push({ type: 'text', raw, text: raw, escaped: false } as Tokens.Text);
+            tokens.push({ type: 'text', raw, text: raw, escaped: this.state.inRawBlock } as Tokens.Text);

With this on master, both examples above render as in 18.2.0. test:specs passes (2079/2079). test:unit has the same 5 failures as unmodified master in my environment, with nothing new. Happy to open a PR with a spec fixture if that helps.

Expected behavior

Text inside inline <script> / <code> / <pre> / <kbd> is output unchanged, as in 18.2.0

Lingua principale
TypeScript
Stelle
37.3k
Fork
3.9k
Merge medio
5g 6h
PR unite (30g)
62

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di markedjs/marked

Tutte le issue di markedjs/marked

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.