Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-laws-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: properly handle percent-encoded anchors (e.g. `<a href="#sparkles-%E2%9C%A8">`) during prerendering.
6 changes: 3 additions & 3 deletions packages/kit/src/core/postbuild/crawl.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 6 additions & 15 deletions packages/kit/src/core/postbuild/crawl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<body>
<a href="#sparkles-%E2%9C%A8">✨</a>
<h1 id="sparkles-%E2%9C%A8">Title</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"hrefs": ["/#sparkles-%E2%9C%A8"],
"ids": ["sparkles-✨"]
}
Loading