From a1947cfabb56873d99199658daf9a62ebfea3c86 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 12 Nov 2026 20:45:37 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Keep=20a=20literal=20back?= =?UTF-8?q?slash=20before=20a=20space=20in=20link=20destinations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdown_it/helpers/parse_link_destination.py | 5 ++++- tests/test_port/fixtures/commonmark_extras.md | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/markdown_it/helpers/parse_link_destination.py b/markdown_it/helpers/parse_link_destination.py index c98323c0..e4859fbb 100644 --- a/markdown_it/helpers/parse_link_destination.py +++ b/markdown_it/helpers/parse_link_destination.py @@ -56,7 +56,10 @@ def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result: if code == 0x5C and pos + 1 < maximum: if charCodeAt(string, pos + 1) == 0x20: - break + # a backslash before a space is a literal backslash, + # and the space then ends the destination + 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..88b22588 100644 --- a/tests/test_port/fixtures/commonmark_extras.md +++ b/tests/test_port/fixtures/commonmark_extras.md @@ -324,6 +324,21 @@ Escaped space is not allowed in link destination, commonmark/CommonMark#493.

[link](a\ b)

. +Backslash before a space in a link destination is a literal backslash, and the space ends the destination (CommonMark 0.31.2 6.3) +. +[a](/url\ ) + +[b](/url\ "title") + +[c] + +[c]: /url\ "title" +. +

a

+

b

+

c

+. + Link destination cannot contain '<' . []()