Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Unreleased

### 🐛 Fixed

* 🐛 Require whitespace between a link reference destination and its multiline title, preserving malformed definitions as paragraph text.

## 4.3.0 - 2026-11-10

This release fixes two quadratic-time parsing paths that let crafted input stall rendering for minutes (security),
Expand Down
4 changes: 2 additions & 2 deletions markdown_it/rules_block/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def reference(state: StateBlock, startLine: int, _endLine: int, silent: bool) ->

# [label]: destination 'title'
# ^^^ skipping those spaces
start = pos
while pos < maximum:
ch = charCodeAt(string, pos)
if ch == 0x0A:
Expand All @@ -107,6 +106,7 @@ def reference(state: StateBlock, startLine: int, _endLine: int, silent: bool) ->

# [label]: destination 'title'
# ^^^^^^^ parse this
titleStart = pos
titleRes = state.md.helpers.parseLinkTitle(string, pos, maximum, None)
while titleRes.can_continue:
if (lineContent := getNextLine(state, nextLine)) is None:
Expand All @@ -117,7 +117,7 @@ def reference(state: StateBlock, startLine: int, _endLine: int, silent: bool) ->
nextLine += 1
titleRes = state.md.helpers.parseLinkTitle(string, pos, maximum, titleRes)

if pos < maximum and start != pos and titleRes.ok:
if pos < maximum and titleStart != destEndPos and titleRes.ok:
title = titleRes.str
pos = titleRes.pos
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_port/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ def test_inline_definitions(data_regression):
src = '[a]: url "title"\n- [a]: url "title"'
tokens = md.parse(src)
data_regression.check([token.as_dict() for token in tokens])


def test_multiline_reference_title_requires_whitespace() -> None:
"""A title glued to its destination leaves both lines in the paragraph."""
md = MarkdownIt()
src = '[guide]\n\n[guide]: <guide.md>"First line\nsecond line"\n'
env: dict[str, object] = {}
tokens = md.parse(src, env)
assert [token.map for token in tokens if token.type == "paragraph_open"] == [
[0, 1],
[2, 4],
]
assert "references" not in env
Loading