Skip to content

Commit

Permalink
fix: decode static file paths (#2642)
Browse files Browse the repository at this point in the history
Fixes #2613
  • Loading branch information
felix-schindler authored Sep 6, 2024
1 parent 03ef0e5 commit 126f492
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/middlewares/static_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function staticFiles<T>(): MiddlewareFn<T> {
const { req, url, config } = ctx;
const buildCache = getBuildCache(ctx);

let pathname = url.pathname;
let pathname = decodeURIComponent(url.pathname);
if (config.basePath) {
pathname = pathname !== config.basePath
? pathname.slice(config.basePath.length)
Expand Down
24 changes: 24 additions & 0 deletions src/middlewares/static_files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,27 @@ Deno.test("static files - enables caching in production", async () => {
"public, max-age=31536000, immutable",
);
});

Deno.test("static files - decoded pathname", async () => {
const buildCache = new MockBuildCache({
"C#.svg": { content: "body {}", hash: null },
"西安市.png": { content: "body {}", hash: null },
"인천.avif": { content: "body {}", hash: null },
});
const server = serveMiddleware(
staticFiles(),
{ buildCache },
);

for (
const path of [
"C%23.svg",
"%E8%A5%BF%E5%AE%89%E5%B8%82.png",
"%EC%9D%B8%EC%B2%9C.avif",
]
) {
const res = await server.get("/" + path);
await res.body?.cancel();
expect(res.status).toEqual(200);
}
});

0 comments on commit 126f492

Please sign in to comment.