Skip to content

Commit 86626ba

Browse files
authored
[fix] handle hash links with non-ASCII characters when prerendering (#7729)
fixes #7728
1 parent 284b20b commit 86626ba

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

.changeset/new-kangaroos-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Handle hash links with non-ASCII characters when prerendering
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<h2 id="before">before</h2>
22
<span data-x='"\\"'>backslash</span>
3-
<h2 id="after">after</h2>
3+
<h2 id="after">after</h2>
4+
<h2 id="encöded">
5+
<a href="#encöded">encöded</a>
6+
</h2>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"hrefs": [],
3-
"ids": ["before", "after"]
2+
"hrefs": ["#encöded"],
3+
"ids": ["before", "after", "encöded"]
44
}

packages/kit/src/core/prerender/prerender.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export async function prerender() {
137137
config.prerender.handleMissingId,
138138
({ path, id, referrers }) => {
139139
return (
140-
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path}:` +
140+
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path} - see the \`handleMissingId\` option in https://kit.svelte.dev/docs/configuration#prerender for more info:` +
141141
referrers.map((l) => `\n - ${l}`).join('')
142142
);
143143
}
@@ -262,11 +262,13 @@ export async function prerender() {
262262
}
263263

264264
if (hash) {
265-
if (!expected_hashlinks.has(pathname + hash)) {
266-
expected_hashlinks.set(pathname + hash, new Set());
265+
const key = decodeURI(pathname + hash);
266+
267+
if (!expected_hashlinks.has(key)) {
268+
expected_hashlinks.set(key, new Set());
267269
}
268270

269-
/** @type {Set<string>} */ (expected_hashlinks.get(pathname + hash)).add(decoded);
271+
/** @type {Set<string>} */ (expected_hashlinks.get(key)).add(decoded);
270272
}
271273

272274
enqueue(decoded, decodeURI(pathname), pathname);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2 id="encöded">
2+
<a href="#encöded">encöded</a>
3+
</h2>

0 commit comments

Comments
 (0)