Skip to content

Commit c7ee43a

Browse files
fix: strip whitespace when normalizing link reference labels (#4091)
1 parent cead8de commit c7ee43a

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎src/helpers.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ export function trimTrailingBlankLines(str: string) {
146146
* keeps the folded label lower case, the form `def.tag` has always used.
147147
*/
148148
export function normalizeLabel(label: string) {
149-
return label.toLowerCase().toUpperCase().toLowerCase();
149+
// The spec also asks for leading and trailing spaces, tabs and line endings
150+
// to be stripped. Doing it here keeps every call site in agreement: the
151+
// definition and the reference have to normalize to the same key.
152+
return label.trim().toLowerCase().toUpperCase().toLowerCase();
150153
}
151154

152155
export function findClosingBracket(str: string, b: string) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p><a href="/foo">foo </a></p>
2+
<p><a href="/bar"> bar</a></p>
3+
<p><a href="/baz">baz</a></p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[foo ]
2+
3+
[ bar]
4+
5+
[baz]
6+
7+
[foo]: /foo
8+
[bar]: /bar
9+
[baz ]: /baz

0 commit comments

Comments
 (0)