Skip to content

Commit 3a9b78f

Browse files
authoredOct 25, 2024··
fix: decode URI when previewing prerendered pages (#12874)
fixes #12865 The issue only affected the preview server as we weren't decoding the URI before checking if the prerendered file existed or not
1 parent dcbe422 commit 3a9b78f

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed
 

‎.changeset/eleven-turkeys-jump.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: decode non-latin characters when previewing prerendered pages

‎packages/kit/src/exports/vite/preview/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ export async function preview(vite, vite_config, svelte_config) {
131131
let filename = normalizePath(
132132
join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
133133
);
134+
135+
try {
136+
filename = decodeURI(filename);
137+
} catch {
138+
// malformed URI
139+
}
140+
134141
let prerendered = is_file(filename);
135142

136143
if (!prerendered) {

‎packages/kit/test/apps/basics/src/routes/prerendering/中文/+page.svelte

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const prerender = true;

‎packages/kit/test/apps/basics/test/server.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ test.describe('Miscellaneous', () => {
630630
expect(response.status()).toBe(200);
631631
expect(await response.text()).toBe('foo');
632632
});
633+
634+
test('serves prerendered non-latin pages', async ({ request }) => {
635+
const response = await request.get('/prerendering/中文');
636+
expect(response.status()).toBe(200);
637+
});
633638
});
634639

635640
test.describe('reroute', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.