diff options
author | uki00a <uki00a@gmail.com> | 2020-10-26 22:55:26 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 14:55:26 +0100 |
commit | b65171e37df066cf7c509434c611163fc8a3c720 (patch) | |
tree | 027f3f1f5d6533383f51a4ede047b961c3fc4e80 /std/http/file_server.ts | |
parent | 57cad539457dff7fc273bed5ecaf08bd3dc40d1b (diff) |
fix(std/http/file_server): File server should ignore query params (#8116)
Diffstat (limited to 'std/http/file_server.ts')
-rw-r--r-- | std/http/file_server.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts index d8751eb84..e4c8c4931 100644 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -321,6 +321,21 @@ function html(strings: TemplateStringsArray, ...values: unknown[]): string { return html; } +function normalizeURL(url: string): string { + let normalizedUrl = posix.normalize(url); + try { + normalizedUrl = decodeURIComponent(normalizedUrl); + } catch (e) { + if (!(e instanceof URIError)) { + throw e; + } + } + const startOfParams = normalizedUrl.indexOf("?"); + return startOfParams > -1 + ? normalizedUrl.slice(0, startOfParams) + : normalizedUrl; +} + function main(): void { const CORSEnabled = serverArgs.cors ? true : false; const port = serverArgs.port ?? serverArgs.p ?? 4507; @@ -362,14 +377,7 @@ function main(): void { } const handler = async (req: ServerRequest): Promise<void> => { - let normalizedUrl = posix.normalize(req.url); - try { - normalizedUrl = decodeURIComponent(normalizedUrl); - } catch (e) { - if (!(e instanceof URIError)) { - throw e; - } - } + const normalizedUrl = normalizeURL(req.url); const fsPath = posix.join(target, normalizedUrl); let response: Response | undefined; |