Skip to content

Commit

Permalink
fix: decoding uri in file_server (#3187)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrukTad authored and ry committed Dec 10, 2019
1 parent ec7f3ce commit 31ddfd5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/http/file_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ listenAndServe(
addr,
async (req): Promise<void> => {
const normalizedUrl = posix.normalize(req.url);
const fsPath = posix.join(target, normalizedUrl);
const decodedUrl = decodeURIComponent(normalizedUrl);
const fsPath = posix.join(target, decodedUrl);

let response: Response;

try {
const info = await stat(fsPath);
if (info.isDirectory()) {
Expand Down
14 changes: 14 additions & 0 deletions std/http/file_server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,17 @@ test(async function serveFallback(): Promise<void> {
killFileServer();
}
});

test(async function serveFallback(): Promise<void> {
await startFileServer();
try {
const res = await fetch(
"https://localhost:4500/http/testdata/test%20file.txt"
);
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assertEquals(res.status, 200);
} finally {
killFileServer();
}
});
Empty file added std/http/testdata/test file.txt
Empty file.

0 comments on commit 31ddfd5

Please sign in to comment.