summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xstd/http/file_server.ts4
-rw-r--r--std/http/file_server_test.ts14
-rw-r--r--std/http/testdata/test file.txt0
3 files changed, 16 insertions, 2 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index fb8f28081..41aac5e45 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -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()) {
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts
index 7d7e024e7..f725b32a2 100644
--- a/std/http/file_server_test.ts
+++ b/std/http/file_server_test.ts
@@ -79,3 +79,17 @@ test(async function serveFallback(): Promise<void> {
killFileServer();
}
});
+
+test(async function serveFallback(): Promise<void> {
+ await startFileServer();
+ try {
+ const res = await fetch(
+ "http://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();
+ }
+});
diff --git a/std/http/testdata/test file.txt b/std/http/testdata/test file.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/std/http/testdata/test file.txt