fix: serve static file with parens (#2013)
This commit is contained in:
+2
-15
@@ -266,9 +266,8 @@ export class ServerContext {
|
|||||||
const { localUrl, path, size, contentType, etag } of this.#extractResult
|
const { localUrl, path, size, contentType, etag } of this.#extractResult
|
||||||
.staticFiles
|
.staticFiles
|
||||||
) {
|
) {
|
||||||
const route = sanitizePathToRegex(path);
|
staticRoutes[path] = {
|
||||||
staticRoutes[route] = {
|
baseRoute: toBaseRoute(path),
|
||||||
baseRoute: toBaseRoute(route),
|
|
||||||
methods: {
|
methods: {
|
||||||
"HEAD": this.#staticFileHandler(
|
"HEAD": this.#staticFileHandler(
|
||||||
localUrl,
|
localUrl,
|
||||||
@@ -589,18 +588,6 @@ export function normalizeURLPath(path: string): string | null {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizePathToRegex(path: string): string {
|
|
||||||
return path
|
|
||||||
.replaceAll("\*", "\\*")
|
|
||||||
.replaceAll("\+", "\\+")
|
|
||||||
.replaceAll("\?", "\\?")
|
|
||||||
.replaceAll("\{", "\\{")
|
|
||||||
.replaceAll("\}", "\\}")
|
|
||||||
.replaceAll("\(", "\\(")
|
|
||||||
.replaceAll("\)", "\\)")
|
|
||||||
.replaceAll("\:", "\\:");
|
|
||||||
}
|
|
||||||
|
|
||||||
function serializeCSPDirectives(csp: ContentSecurityPolicyDirectives): string {
|
function serializeCSPDirectives(csp: ContentSecurityPolicyDirectives): string {
|
||||||
return Object.entries(csp)
|
return Object.entries(csp)
|
||||||
.filter(([_key, value]) => value !== undefined)
|
.filter(([_key, value]) => value !== undefined)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
it works
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
it works
|
||||||
@@ -359,6 +359,16 @@ Deno.test("static file - by file path", async () => {
|
|||||||
assertEquals(resp3.headers.get("content-type"), "text/plain");
|
assertEquals(resp3.headers.get("content-type"), "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("static file - spaces or other characters in name", async () => {
|
||||||
|
const res = await handler(new Request("https://fresh.deno.dev/foo bar.txt"));
|
||||||
|
assertEquals(await res.text(), "it works");
|
||||||
|
|
||||||
|
const res2 = await handler(
|
||||||
|
new Request("https://fresh.deno.dev/foo (bar).txt"),
|
||||||
|
);
|
||||||
|
assertEquals(await res2.text(), "it works");
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test("HEAD request", async () => {
|
Deno.test("HEAD request", async () => {
|
||||||
// Static file
|
// Static file
|
||||||
const resp = await handler(
|
const resp = await handler(
|
||||||
|
|||||||
Reference in New Issue
Block a user