summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xstd/http/file_server.ts12
-rw-r--r--std/http/file_server_test.ts11
-rw-r--r--std/http/testdata/%0
3 files changed, 16 insertions, 7 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index acf272764..d71b9ad53 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -301,9 +301,15 @@ function html(strings: TemplateStringsArray, ...values: unknown[]): string {
listenAndServe(
addr,
async (req): Promise<void> => {
- const normalizedUrl = posix.normalize(req.url);
- const decodedUrl = decodeURIComponent(normalizedUrl);
- const fsPath = posix.join(target, decodedUrl);
+ let normalizedUrl = posix.normalize(req.url);
+ try {
+ normalizedUrl = decodeURIComponent(normalizedUrl);
+ } catch (e) {
+ if (!(e instanceof URIError)) {
+ throw e;
+ }
+ }
+ const fsPath = posix.join(target, normalizedUrl);
let response: Response;
try {
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts
index ba625b7c8..0329168e7 100644
--- a/std/http/file_server_test.ts
+++ b/std/http/file_server_test.ts
@@ -83,12 +83,15 @@ test(async function serveFallback(): Promise<void> {
}
});
-test(async function serveFallback(): Promise<void> {
+test(async function serveWithUnorthodoxFilename(): Promise<void> {
await startFileServer();
try {
- const res = await fetch(
- "http://localhost:4500/http/testdata/test%20file.txt"
- );
+ let res = await fetch("http://localhost:4500/http/testdata/%");
+ assert(res.headers.has("access-control-allow-origin"));
+ assert(res.headers.has("access-control-allow-headers"));
+ assertEquals(res.status, 200);
+
+ 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);
diff --git a/std/http/testdata/% b/std/http/testdata/%
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/std/http/testdata/%