Skip to content

Commit

Permalink
fix: decode URI when previewing prerendered pages (#12874)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eltigerchino authored Oct 25, 2024
1 parent dcbe422 commit 3a9b78f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-turkeys-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: decode non-latin characters when previewing prerendered pages
7 changes: 7 additions & 0 deletions packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ export async function preview(vite, vite_config, svelte_config) {
let filename = normalizePath(
join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
);

try {
filename = decodeURI(filename);
} catch {
// malformed URI
}

let prerendered = is_file(filename);

if (!prerendered) {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
5 changes: 5 additions & 0 deletions packages/kit/test/apps/basics/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ test.describe('Miscellaneous', () => {
expect(response.status()).toBe(200);
expect(await response.text()).toBe('foo');
});

test('serves prerendered non-latin pages', async ({ request }) => {
const response = await request.get('/prerendering/中文');
expect(response.status()).toBe(200);
});
});

test.describe('reroute', () => {
Expand Down

0 comments on commit 3a9b78f

Please sign in to comment.