Skip to content

Commit

Permalink
fix: decode asset URLs in dev when reading them (#12341)
Browse files Browse the repository at this point in the history
* update test

* decode asset URLs in dev when reading them

* changeset
  • Loading branch information
Rich-Harris authored Jun 14, 2024
1 parent 9e48352 commit be72092
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-bees-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: decode asset URLs in dev when reading them
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function read(asset) {
});
}

const file = DEV && asset.startsWith('/@fs') ? asset : asset.slice(base.length + 1);
const file =
DEV && asset.startsWith('/@fs') ? decodeURIComponent(asset) : asset.slice(base.length + 1);

if (file in manifest._.server_assets) {
const length = manifest._.server_assets[file];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { read } from '$app/server';
import auto from './auto.txt';
import url from './url.txt?url';

const glob = import.meta.glob('../../../../read-file-test.txt', {
as: 'url',
/** @type {Record<string, { default: string }>} */
const glob = import.meta.glob('../../../../read-file-test/**', {
query: '?url',
eager: true
});

Expand All @@ -16,6 +17,6 @@ export async function load() {
return {
auto: await read(auto).text(),
url: await read(url).text(),
glob: await read(Object.values(glob)[0]).text()
glob: await read(Object.values(glob)[0].default).text()
};
}
File renamed without changes.

0 comments on commit be72092

Please sign in to comment.