fix: ensure we decode uri encoded filenames

This commit is contained in:
Andy Burke 2025-08-12 15:33:32 -07:00
parent 278a39a47b
commit 55f45b4e5b
3 changed files with 8 additions and 5 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "@andyburke/serverus", "name": "@andyburke/serverus",
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.", "description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
"version": "0.12.4", "version": "0.12.5",
"license": "MIT", "license": "MIT",
"exports": { "exports": {
".": "./serverus.ts", ".": "./serverus.ts",

View file

@ -279,7 +279,7 @@ export default async function handle_static_files(request: Request, server: SERV
} }
const url = new URL(request.url); const url = new URL(request.url);
const normalized_path = path.resolve(path.normalize(url.pathname).replace(/^\/+/, '')); const normalized_path = path.resolve(path.normalize(decodeURIComponent(url.pathname)).replace(/^\/+/, ''));
// if they're requesting something outside the working dir, just bail // if they're requesting something outside the working dir, just bail
if (!normalized_path.startsWith(Deno.cwd())) { if (!normalized_path.startsWith(Deno.cwd())) {

View file

@ -321,9 +321,12 @@ Deno.test({
put_body.delete('file'); put_body.delete('file');
test_file = undefined; test_file = undefined;
const get_response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/files/2Q==(30).txt`, { const get_response = await fetch(
method: 'GET' `http://${test_server_info.hostname}:${test_server_info.port}/files/${encodeURIComponent('2Q==(30).txt')}`,
}); {
method: 'GET'
}
);
asserts.assert(get_response.ok); asserts.assert(get_response.ok);
asserts.assert(get_response.body); asserts.assert(get_response.body);