diff --git a/.changeset/clever-bees-float.md b/.changeset/clever-bees-float.md new file mode 100644 index 000000000000..3a7fbf6ff5dd --- /dev/null +++ b/.changeset/clever-bees-float.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: decode asset URLs in dev when reading them diff --git a/packages/kit/src/runtime/app/server/index.js b/packages/kit/src/runtime/app/server/index.js index 3702c171bb6a..2a1ae1765b26 100644 --- a/packages/kit/src/runtime/app/server/index.js +++ b/packages/kit/src/runtime/app/server/index.js @@ -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]; diff --git a/packages/kit/test/apps/basics/src/routes/read-file/+page.server.js b/packages/kit/test/apps/basics/src/routes/read-file/+page.server.js index 1b89fef87df1..018f57c4f261 100644 --- a/packages/kit/test/apps/basics/src/routes/read-file/+page.server.js +++ b/packages/kit/test/apps/basics/src/routes/read-file/+page.server.js @@ -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} */ +const glob = import.meta.glob('../../../../read-file-test/**', { + query: '?url', eager: true }); @@ -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() }; } diff --git a/packages/kit/test/apps/read-file-test.txt b/packages/kit/test/apps/read-file-test/[file].txt similarity index 100% rename from packages/kit/test/apps/read-file-test.txt rename to packages/kit/test/apps/read-file-test/[file].txt