diff options
author | 木杉 <zhmushan@qq.com> | 2020-02-12 04:53:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 15:53:09 -0500 |
commit | 92019498f6361c31ad24decfc14e81660959f6cb (patch) | |
tree | 0ce0fb9a5f00916ae7767b5062f7702cfc9a5229 /std/http/file_server.ts | |
parent | b67f20be3b5234bad2565c1770fa89d49942b342 (diff) |
fix(file_server): don't crash on "%" pathname (#3953)
Diffstat (limited to 'std/http/file_server.ts')
-rwxr-xr-x | std/http/file_server.ts | 12 |
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 { |