From fe0d3496e940442f7df964e28030034512cb050f Mon Sep 17 00:00:00 2001 From: simple-minded <191973953+hakarrr@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:48:02 +0530 Subject: [PATCH] fix: preserve Unicode whitespace in inline link destinations (#4249) * fix: preserve Unicode whitespace in inline link destinations Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * fix: preserve Unicode whitespace in inline link destinations Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * fix: preserve Unicode whitespace in inline link destinations Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: migrate reviewed regression to native fixture Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: migrate reviewed regression to native fixture Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: migrate reviewed regression to native fixture Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: migrate reviewed regression to native fixture Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: remove superseded regression after native fixture migration Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: remove superseded regression after native fixture migration Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: remove unrelated ASCII-tab link destination fixture Remove the input identified in review. The existing parser mismatch is outside this Unicode-whitespace change; the corresponding expected output is removed in the companion commit. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> * test: align link destination output with removed ASCII-tab case Remove only the expected output corresponding to the reviewed ASCII-tab input. Unicode cases remain unchanged; this does not fix the separate parser mismatch. Full local npm test passed: 2039 specs and 256 unit tests. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --------- Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --- src/Tokenizer.ts | 6 +- .../link_destination_unicode_whitespace.html | 99 +++++++++ .../link_destination_unicode_whitespace.md | 204 ++++++++++++++++++ .../link_destination_whitespace_pedantic.html | 1 + .../link_destination_whitespace_pedantic.md | 6 + 5 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/link_destination_unicode_whitespace.html create mode 100644 test/specs/new/link_destination_unicode_whitespace.md create mode 100644 test/specs/new/link_destination_whitespace_pedantic.html create mode 100644 test/specs/new/link_destination_whitespace_pedantic.md diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 3b2cc1ea..3cd1b8b3 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -985,7 +985,11 @@ export class _Tokenizer { title = cap[3] ? cap[3].slice(1, -1) : ''; } - href = href.trim(); + // Modern link rules already separate ASCII whitespace from the destination. + // Other whitespace is destination content and must not be trimmed. + if (this.options.pedantic) { + href = href.trim(); + } if (this.rules.other.startAngleBracket.test(href)) { if (this.options.pedantic && !(this.rules.other.endAngleBracket.test(trimmedUrl))) { // pedantic allows starting angle bracket without ending angle bracket diff --git a/test/specs/new/link_destination_unicode_whitespace.html b/test/specs/new/link_destination_unicode_whitespace.html new file mode 100644 index 00000000..57d11c87 --- /dev/null +++ b/test/specs/new/link_destination_unicode_whitespace.html @@ -0,0 +1,99 @@ +

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+
+

x

+

x

+

x

diff --git a/test/specs/new/link_destination_unicode_whitespace.md b/test/specs/new/link_destination_unicode_whitespace.md new file mode 100644 index 00000000..888e5298 --- /dev/null +++ b/test/specs/new/link_destination_unicode_whitespace.md @@ -0,0 +1,204 @@ +--- +gfm: true +renderExact: true +--- + +[x]( /url) + +--- + +[x](/url ) + +--- + +[x]( /url ) + +--- + +![x]( /url) + +--- + +![x](/url ) + +--- + +![x]( /url ) + +--- + +[x]( /url) + +--- + +[x](/url ) + +--- + +[x]( /url ) + +--- + +![x]( /url) + +--- + +![x](/url ) + +--- + +![x]( /url ) + +--- + +[x]( /url) + +--- + +[x](/url ) + +--- + +[x]( /url ) + +--- + +![x]( /url) + +--- + +![x](/url ) + +--- + +![x]( /url ) + +--- + +[x](
/url) + +--- + +[x](/url
) + +--- + +[x](
/url
) + +--- + +![x](
/url) + +--- + +![x](/url
) + +--- + +![x](
/url
) + +--- + +[x](
/url) + +--- + +[x](/url
) + +--- + +[x](
/url
) + +--- + +![x](
/url) + +--- + +![x](/url
) + +--- + +![x](
/url
) + +--- + +[x]( /url) + +--- + +[x](/url ) + +--- + +[x]( /url ) + +--- + +![x]( /url) + +--- + +![x](/url ) + +--- + +![x]( /url ) + +--- + +[x]( /url) + +--- + +[x](/url ) + +--- + +[x]( /url ) + +--- + +![x]( /url) + +--- + +![x](/url ) + +--- + +![x]( /url ) + +--- + +[x](/url) + +--- + +[x](/url) + +--- + +[x](/url) + +--- + +![x](/url) + +--- + +![x](/url) + +--- + +![x](/url) + +--- + +[x]( +/url +) + +[x](< /url > "title") + +[x]( /url  "title") diff --git a/test/specs/new/link_destination_whitespace_pedantic.html b/test/specs/new/link_destination_whitespace_pedantic.html new file mode 100644 index 00000000..6e086a99 --- /dev/null +++ b/test/specs/new/link_destination_whitespace_pedantic.html @@ -0,0 +1 @@ +

x

diff --git a/test/specs/new/link_destination_whitespace_pedantic.md b/test/specs/new/link_destination_whitespace_pedantic.md new file mode 100644 index 00000000..65f810f5 --- /dev/null +++ b/test/specs/new/link_destination_whitespace_pedantic.md @@ -0,0 +1,6 @@ +--- +pedantic: true +renderExact: true +--- + +[x]( /url )