From 1d95170f1e87c9c78846ee22cf1f4c9970938007 Mon Sep 17 00:00:00 2001 From: draarivpatel-ui <287273626+draarivpatel-ui@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:34:54 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Keep=20literal=20backslas?= =?UTF-8?q?hes=20before=20spaces=20in=20link=20destinations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A backslash before a space is literal, not an escape. Keep it in an unbracketed destination and let the following space terminate the destination, matching CommonMark and markdown-it 15. --- CHANGELOG.md | 6 +++++ markdown_it/helpers/parse_link_destination.py | 3 ++- tests/test_port/fixtures/commonmark_extras.md | 23 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) 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\ ) +. + +. + +Backslash before a space in a link destination, followed by a title. +. +[a](/url\ "title") +. + +. + +Backslash before a space in a reference destination. +. +[a]: /url\ "title" + +[a] +. + +.