summaryrefslogtreecommitdiff
path: root/std/http/file_server.ts
diff options
context:
space:
mode:
author木杉 <zhmushan@qq.com>2020-02-12 04:53:09 +0800
committerGitHub <noreply@github.com>2020-02-11 15:53:09 -0500
commit92019498f6361c31ad24decfc14e81660959f6cb (patch)
tree0ce0fb9a5f00916ae7767b5062f7702cfc9a5229 /std/http/file_server.ts
parentb67f20be3b5234bad2565c1770fa89d49942b342 (diff)
fix(file_server): don't crash on "%" pathname (#3953)
Diffstat (limited to 'std/http/file_server.ts')
-rwxr-xr-xstd/http/file_server.ts12
1 files changed, 9 insertions, 3 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 {