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:
parent
b67f20be3b
commit
92019498f6
3 changed files with 16 additions and 7 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
0
std/http/testdata/%
vendored
Normal file
Loading…
Reference in a new issue