Skip to content

🐛 fix(markdown): stop backtick languages breaking code fences - #2153

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/uhi730vw
Nov 15, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/uhi730vw

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

A <pre> whose language class held a backtick exported to Markdown as a broken code block. 🧾 CommonMark allows a backtick fence only when its info string holds no backtick. The serializer wrote the backtick anyway, so the opening line became paragraph text, and the code that followed was read as Markdown and raw HTML. Readers of the exported Markdown could see markup where the page had code. After this change such a language is ignored, and the block keeps its fence and its text stays code.

The three ways a <pre> names its language, its own class, the class of its sole <code> child, and a styled <pre>, all go through one language lookup, so one check there covers all three. The Markdown.Code(language=...) fallback is checked the same way, because the application supplies it and a backtick in it breaks the fence just as well.

Behavior changes

  • A language-* class that holds a backtick names no language. The lookup moves on to the next such class, then to the <pre>'s own class, then to the fallback.
  • A Markdown.Code(language=...) value that holds a backtick is not written, so those fences carry no language.
  • Every language without a backtick produces the same output as before.

Fixes #1771.

A backtick cannot appear in the info string of a backtick code fence.
A language-* class holding one, or a Markdown.Code language holding one,
was written into the fence anyway, so the opening line stopped being a
fence and the code text was read as Markdown and raw HTML. Such a
language is now skipped: a class token falls through to the next
candidate, and a fallback holding a backtick is not written.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 24.98%

2 warnings

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

❌ 1 regressed benchmark
✅ 581 untouched benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_mutating_feature[path-xpath-one-cold] 107.2 µs 142.9 µs -24.98%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:sec-fix/uhi730vw (9ae77b3) with main (127bfde)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit 8e3c254 into tox-dev:main Nov 15, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_markdown() breaks a code block when its language class contains a backtick

1 participant