Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure correct case is used for static assets #5047

Merged
merged 3 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved

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');
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status()).toBe(404);
});
});

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