Skip to content

Commit

Permalink
ensure correct case is used for static assets - closes #4931
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 24, 2022
1 parent 948c980 commit 1f2269f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-actors-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

ensure static assets are only served if correct case is used
12 changes: 9 additions & 3 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,15 @@ export async function create_plugin(config) {
const file = config.kit.files.assets + pathname;

if (fs.existsSync(file) && !fs.statSync(file).isDirectory()) {
req.url = encodeURI(pathname); // don't need query/hash
asset_server(req, res);
return;
const has_correct_case = fs
.readdirSync(path.dirname(file))
.includes(path.basename(file));

if (has_correct_case) {
req.url = encodeURI(pathname); // don't need query/hash
asset_server(req, res);
return;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,11 @@ test.describe.parallel('Static files', () => {
const response = await request.get(path);
expect(response.status()).toBe(200);
});

test('Filenames are case-sensitive', async ({ request }) => {
let response = await request.get('/static.JSON');
expect(response.status()).toBe(404);
});
});

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

0 comments on commit 1f2269f

Please sign in to comment.