fix: strip whitespace when normalizing link reference labels (#4091)

This commit is contained in:
Ngo Quoc Viet
2026-09-20 20:53:06 -06:00
committed by GitHub
parent cead8de96f
commit c7ee43abec
3 changed files with 16 additions and 1 deletions
+4 -1
View File
@@ -146,7 +146,10 @@ export function trimTrailingBlankLines(str: string) {
* keeps the folded label lower case, the form `def.tag` has always used.
*/
export function normalizeLabel(label: string) {
return label.toLowerCase().toUpperCase().toLowerCase();
// The spec also asks for leading and trailing spaces, tabs and line endings
// to be stripped. Doing it here keeps every call site in agreement: the
// definition and the reference have to normalize to the same key.
return label.trim().toLowerCase().toUpperCase().toLowerCase();
}
export function findClosingBracket(str: string, b: string) {
@@ -0,0 +1,3 @@
<p><a href="/foo">foo </a></p>
<p><a href="/bar"> bar</a></p>
<p><a href="/baz">baz</a></p>
@@ -0,0 +1,9 @@
[foo ]
[ bar]
[baz]
[foo]: /foo
[bar]: /bar
[baz ]: /baz