diff --git a/CHANGELOG.md b/CHANGELOG.md index c411d126..5ef5caca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## Unreleased + +### 🐛 Fixed + +* 🐛 Keep a literal backslash before a space in link and image destinations, so the space ends the destination instead of making the link fail. + ## 4.3.0 - 2026-11-10 This release fixes two quadratic-time parsing paths that let crafted input stall rendering for minutes (security), diff --git a/markdown_it/helpers/parse_link_destination.py b/markdown_it/helpers/parse_link_destination.py index c98323c0..86a0b542 100644 --- a/markdown_it/helpers/parse_link_destination.py +++ b/markdown_it/helpers/parse_link_destination.py @@ -56,7 +56,8 @@ def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result: if code == 0x5C and pos + 1 < maximum: if charCodeAt(string, pos + 1) == 0x20: - break + pos += 1 + continue pos += 2 continue diff --git a/tests/test_port/fixtures/commonmark_extras.md b/tests/test_port/fixtures/commonmark_extras.md index 98ce1ad5..e2b6f004 100644 --- a/tests/test_port/fixtures/commonmark_extras.md +++ b/tests/test_port/fixtures/commonmark_extras.md @@ -880,3 +880,26 @@ foo

foo

. + +Backslash before a space inside a link destination (CommonMark 0.31.2 6.3) is a literal backslash, and the space ends the destination. +. +[a](/url\ ) +. +

a

+. + +Backslash before a space in a link destination, followed by a title. +. +[a](/url\ "title") +. +

a

+. + +Backslash before a space in a reference destination. +. +[a]: /url\ "title" + +[a] +. +

a

+.