1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 00:21:05 -05:00

fix(file_server): don't crash on "%" pathname (#3953)

This commit is contained in:
木杉 2020-02-12 04:53:09 +08:00 committed by GitHub
parent b67f20be3b
commit 92019498f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -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 {

View file

@ -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);

0
std/http/testdata/% vendored Normal file
View file