From 2d77df48e0aeee8f51296ea4891467864f74d0b3 Mon Sep 17 00:00:00 2001 From: Gautier Ben Aim Date: Fri, 30 Jan 2026 23:55:44 +0100 Subject: [PATCH 1/4] fix(kit): properly handle percent-encoded anchors during prerendering --- packages/kit/src/core/postbuild/crawl.js | 6 +++--- .../kit/src/core/postbuild/fixtures/encoded-ids/input.html | 7 +++++++ .../src/core/postbuild/fixtures/encoded-ids/output.json | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 packages/kit/src/core/postbuild/fixtures/encoded-ids/input.html create mode 100644 packages/kit/src/core/postbuild/fixtures/encoded-ids/output.json diff --git a/packages/kit/src/core/postbuild/crawl.js b/packages/kit/src/core/postbuild/crawl.js index caffef583c55..25134d1b4fe9 100644 --- a/packages/kit/src/core/postbuild/crawl.js +++ b/packages/kit/src/core/postbuild/crawl.js @@ -1,4 +1,4 @@ -import { resolve } from '../../utils/url.js'; +import { resolve, decode_uri } from '../../utils/url.js'; import { decode } from './entities.js'; const DOCTYPE = 'DOCTYPE'; @@ -193,11 +193,11 @@ export function crawl(html, base) { } if (id) { - ids.push(id); + ids.push(decode_uri(id)); } if (name && tag === 'A') { - ids.push(name); + ids.push(decode_uri(name)); } if (src) { diff --git a/packages/kit/src/core/postbuild/fixtures/encoded-ids/input.html b/packages/kit/src/core/postbuild/fixtures/encoded-ids/input.html new file mode 100644 index 000000000000..40c5b98acf41 --- /dev/null +++ b/packages/kit/src/core/postbuild/fixtures/encoded-ids/input.html @@ -0,0 +1,7 @@ + + + + +

Title

+ + diff --git a/packages/kit/src/core/postbuild/fixtures/encoded-ids/output.json b/packages/kit/src/core/postbuild/fixtures/encoded-ids/output.json new file mode 100644 index 000000000000..f269cb900a51 --- /dev/null +++ b/packages/kit/src/core/postbuild/fixtures/encoded-ids/output.json @@ -0,0 +1,4 @@ +{ + "hrefs": ["/#sparkles-%E2%9C%A8"], + "ids": ["sparkles-✨"] +} From 257b4dedd7544f9b19895cd995b96ae1e27a7eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ben=20A=C3=AFm?= <48261497+GauBen@users.noreply.github.com> Date: Sat, 31 Jan 2026 00:01:08 +0100 Subject: [PATCH 2/4] changelog --- .changeset/stale-laws-speak.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stale-laws-speak.md diff --git a/.changeset/stale-laws-speak.md b/.changeset/stale-laws-speak.md new file mode 100644 index 000000000000..e0574c0da25b --- /dev/null +++ b/.changeset/stale-laws-speak.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +Properly handle percent-encoded anchors (e.g. ``) during prerendering. From b13c41faaac63ffe52069ce57f6e44214a461ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ben=20A=C3=AFm?= <48261497+GauBen@users.noreply.github.com> Date: Sat, 31 Jan 2026 00:01:52 +0100 Subject: [PATCH 3/4] Apply suggestion from @GauBen --- .changeset/stale-laws-speak.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/stale-laws-speak.md b/.changeset/stale-laws-speak.md index e0574c0da25b..3942be544bf4 100644 --- a/.changeset/stale-laws-speak.md +++ b/.changeset/stale-laws-speak.md @@ -2,4 +2,4 @@ "@sveltejs/kit": patch --- -Properly handle percent-encoded anchors (e.g. ``) during prerendering. +fix: properly handle percent-encoded anchors (e.g. ``) during prerendering. From 86fe785c2bdac0160cbe82726476d63db28842c2 Mon Sep 17 00:00:00 2001 From: Elliott Johnson Date: Fri, 30 Jan 2026 16:26:40 -0700 Subject: [PATCH 4/4] improve tests --- packages/kit/src/core/postbuild/crawl.spec.js | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/kit/src/core/postbuild/crawl.spec.js b/packages/kit/src/core/postbuild/crawl.spec.js index 46a5d4d950bd..616d27dbdf56 100644 --- a/packages/kit/src/core/postbuild/crawl.spec.js +++ b/packages/kit/src/core/postbuild/crawl.spec.js @@ -5,18 +5,9 @@ import { crawl } from './crawl.js'; const fixtures = fileURLToPath(new URL('./fixtures', import.meta.url)); -for (const fixture of fs.readdirSync(fixtures)) { - test(fixture, () => { - const input = fs.readFileSync(`${fixtures}/${fixture}/input.html`, 'utf8'); - const expected = JSON.parse(fs.readFileSync(`${fixtures}/${fixture}/output.json`, 'utf8')); - - // const start = Date.now(); - - const output = crawl(input, '/'); - - // uncomment to see how long it took - // console.error(fixture, Date.now() - start); - - expect(output).toEqual(expected); - }); -} +test.each(fs.readdirSync(fixtures))('%s', (fixture) => { + const input = fs.readFileSync(`${fixtures}/${fixture}/input.html`, 'utf8'); + const expected = JSON.parse(fs.readFileSync(`${fixtures}/${fixture}/output.json`, 'utf8')); + const output = crawl(input, '/'); + expect(output).toEqual(expected); +});