From 469dd0c9025ad1dc55464bf366e4d841d67959f2 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Thu, 4 Jan 2024 17:40:44 +0800 Subject: [PATCH] Preserve leading slash when resolving static paths (#111) Fixes https://github.com/com-lihaoyi/cask/issues/101 --- cask/src/cask/endpoints/StaticEndpoints.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cask/src/cask/endpoints/StaticEndpoints.scala b/cask/src/cask/endpoints/StaticEndpoints.scala index 758579a765..3482451cb6 100644 --- a/cask/src/cask/endpoints/StaticEndpoints.scala +++ b/cask/src/cask/endpoints/StaticEndpoints.scala @@ -4,7 +4,8 @@ import cask.router.{HttpEndpoint, Result} import cask.model.Request object StaticUtil{ def makePathAndContentType(t: String, ctx: Request) = { - val path = (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments) + val leadingSlash = if (t.startsWith("/")) "/" else "" + val path = leadingSlash + (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments) .filter(s => s != "." && s != "..") .mkString("/") val contentType = java.nio.file.Files.probeContentType(java.nio.file.Paths.get(path))