Skip to content

Commit

Permalink
Decode URIs before checking filename against manifest (#3571)
Browse files Browse the repository at this point in the history
* test prerendering file with spaces (#1501)

* decode URIs before matching against manifest

* changeset
  • Loading branch information
Rich-Harris authored Jan 28, 2022
1 parent ae4b0ae commit 27239fa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/proud-buses-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Decode fetched resources before checking against manifest when prerendering
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/load_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function load_node({
// handle fetch requests for static assets. e.g. prebaked data, etc.
// we need to support everything the browser's fetch supports
const prefix = options.paths.assets || options.paths.base;
const filename = (
const filename = decodeURIComponent(
resolved.startsWith(prefix) ? resolved.slice(prefix.length) : resolved
).slice(1);
const filename_html = `${filename}/index.html`; // path may also match path/index.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script context="module">
/** @type {import('@sveltejs/kit').Load} */
export async function load({ fetch }) {
const r1 = await fetch('/file%20with%20spaces.json');
const p1 = await r1.json();
const r2 = await fetch('/file with spaces.json');
const p2 = await r2.json();
if (p1.answer !== p2.answer) {
throw new Error('oops');
}
return {
props: p1
};
}
</script>

<script>
/** @type {number} */
export let answer;
</script>

<h1>answer: {answer}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "answer": 42 }
5 changes: 5 additions & 0 deletions packages/kit/test/prerendering/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ test('renders page with unbuffered data from endpoint', () => {
assert.equal(json, JSON.stringify({ answer: 42 }));
});

test('loads a file with spaces in the filename', () => {
const content = read('load-file-with-spaces/index.html');
assert.ok(content.includes('<h1>answer: 42</h1>'), content);
});

test.run();

0 comments on commit 27239fa

Please sign in to comment.