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

* 🐛 Prevent linkification in link or image labels from stalling or raising a parser progress error, restoring the missing markdown-it 14.1.0 progress check ([#470](https://github.com/executablebooks/markdown-it-py/issues/470)).

## 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: 4 additions & 0 deletions markdown_it/rules_inline/linkify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def linkify(state: StateInline, silent: bool) -> bool:
return False
url: str = link.url

# An invalid match must not leave the parser at the same position or earlier.
if len(url) <= len(proto):
return False

# disallow '*' at the end of the link (conflicts with emphasis)
url = url.rstrip("*")

Expand Down
48 changes: 48 additions & 0 deletions tests/test_linkify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@
pytest.importorskip("linkify_it")


@pytest.mark.parametrize(
"scheme,prefix_length",
[("http", 8), ("http", 9), ("https", 9), ("https", 10), ("ftp", 7), ("ftp", 8)],
)
@pytest.mark.parametrize(
"source,expected",
[
("{prefix}[{url}", "{prefix}[{link}"),
("{prefix}[{url}]", "{prefix}[{link}]"),
(
"{prefix}[{url}](https://example.org)",
'{prefix}<a href="https://example.org">{url}</a>',
),
(
"{prefix}![{url}](image.png)",
'{prefix}<img src="image.png" alt="{url}" />',
),
],
ids=["unclosed", "closed", "link", "image"],
)
def test_linkify_in_link_label(scheme, prefix_length, source, expected):
"""Link-label lookahead must not stall on a stale pending scheme (#470)."""
md = MarkdownIt("gfm-like")
prefix = "a" * prefix_length
url = f"{scheme}://s://"
link = f'<a href="{scheme}://s">{scheme}://s</a>://'
text = source.format(prefix=prefix, url=url)
expected = expected.format(prefix=prefix, url=url, link=link)
assert md.renderInline(text) == expected
assert md.render(text) == f"<p>{expected}</p>\n"


@pytest.mark.parametrize("preset", ["commonmark", "gfm-like"])
def test_link_label_with_linkify_disabled(preset):
"""The progress check must not require linkifying ordinary label text."""
md = MarkdownIt(preset, {"linkify": False})
text = "abcdefgh[http://s://"
assert md.renderInline(text) == text


def test_linkify_inside_emphasis() -> None:
"""Preserve normal linkification and trailing emphasis delimiters."""
md = MarkdownIt("gfm-like")
assert md.renderInline("*https://example.org/*") == (
'<em><a href="https://example.org/">https://example.org/</a></em>'
)


def test_token_levels():
mdit = MarkdownIt(options_update={"linkify": True}).enable("linkify")
tokens = mdit.parse("www.python.org")
Expand Down