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>
This commit is contained in:
simple-minded
2026-11-27 15:18:02 -07:00
committed by GitHub
co-authored by GeneralTony007
parent f3bfaf6699
commit fe0d3496e9
5 changed files with 315 additions and 1 deletions
+5 -1
View File
@@ -985,7 +985,11 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
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
@@ -0,0 +1,99 @@
<p><a href="%C2%A0/url">x</a></p>
<hr>
<p><a href="/url%C2%A0">x</a></p>
<hr>
<p><a href="%C2%A0/url%C2%A0">x</a></p>
<hr>
<p><img src="%C2%A0/url" alt="x"></p>
<hr>
<p><img src="/url%C2%A0" alt="x"></p>
<hr>
<p><img src="%C2%A0/url%C2%A0" alt="x"></p>
<hr>
<p><a href="%E1%9A%80/url">x</a></p>
<hr>
<p><a href="/url%E1%9A%80">x</a></p>
<hr>
<p><a href="%E1%9A%80/url%E1%9A%80">x</a></p>
<hr>
<p><img src="%E1%9A%80/url" alt="x"></p>
<hr>
<p><img src="/url%E1%9A%80" alt="x"></p>
<hr>
<p><img src="%E1%9A%80/url%E1%9A%80" alt="x"></p>
<hr>
<p><a href="%E2%80%83/url">x</a></p>
<hr>
<p><a href="/url%E2%80%83">x</a></p>
<hr>
<p><a href="%E2%80%83/url%E2%80%83">x</a></p>
<hr>
<p><img src="%E2%80%83/url" alt="x"></p>
<hr>
<p><img src="/url%E2%80%83" alt="x"></p>
<hr>
<p><img src="%E2%80%83/url%E2%80%83" alt="x"></p>
<hr>
<p><a href="%E2%80%A8/url">x</a></p>
<hr>
<p><a href="/url%E2%80%A8">x</a></p>
<hr>
<p><a href="%E2%80%A8/url%E2%80%A8">x</a></p>
<hr>
<p><img src="%E2%80%A8/url" alt="x"></p>
<hr>
<p><img src="/url%E2%80%A8" alt="x"></p>
<hr>
<p><img src="%E2%80%A8/url%E2%80%A8" alt="x"></p>
<hr>
<p><a href="%E2%80%A9/url">x</a></p>
<hr>
<p><a href="/url%E2%80%A9">x</a></p>
<hr>
<p><a href="%E2%80%A9/url%E2%80%A9">x</a></p>
<hr>
<p><img src="%E2%80%A9/url" alt="x"></p>
<hr>
<p><img src="/url%E2%80%A9" alt="x"></p>
<hr>
<p><img src="%E2%80%A9/url%E2%80%A9" alt="x"></p>
<hr>
<p><a href="%E2%80%AF/url">x</a></p>
<hr>
<p><a href="/url%E2%80%AF">x</a></p>
<hr>
<p><a href="%E2%80%AF/url%E2%80%AF">x</a></p>
<hr>
<p><img src="%E2%80%AF/url" alt="x"></p>
<hr>
<p><img src="/url%E2%80%AF" alt="x"></p>
<hr>
<p><img src="%E2%80%AF/url%E2%80%AF" alt="x"></p>
<hr>
<p><a href="%E3%80%80/url">x</a></p>
<hr>
<p><a href="/url%E3%80%80">x</a></p>
<hr>
<p><a href="%E3%80%80/url%E3%80%80">x</a></p>
<hr>
<p><img src="%E3%80%80/url" alt="x"></p>
<hr>
<p><img src="/url%E3%80%80" alt="x"></p>
<hr>
<p><img src="%E3%80%80/url%E3%80%80" alt="x"></p>
<hr>
<p><a href="%EF%BB%BF/url">x</a></p>
<hr>
<p><a href="/url%EF%BB%BF">x</a></p>
<hr>
<p><a href="%EF%BB%BF/url%EF%BB%BF">x</a></p>
<hr>
<p><img src="%EF%BB%BF/url" alt="x"></p>
<hr>
<p><img src="/url%EF%BB%BF" alt="x"></p>
<hr>
<p><img src="%EF%BB%BF/url%EF%BB%BF" alt="x"></p>
<hr>
<p><a href="/url">x</a></p>
<p><a href="%C2%A0/url%C2%A0" title="title">x</a></p>
<p><a href="%C2%A0/url%C2%A0" title="title">x</a></p>
@@ -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")
@@ -0,0 +1 @@
<p><a href="/url">x</a></p>
@@ -0,0 +1,6 @@
---
pedantic: true
renderExact: true
---
[x]( /url )