Skip to content

Commit

Permalink
0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Aug 25, 2018
1 parent 8304925 commit ece16bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cask/src/cask/endpoints/StaticEndpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class staticFiles(val path: String) extends Endpoint{
type InputParser[T] = QueryParamReader[T]
override def subpath = true
def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
delegate(Map()).map(t => cask.model.StaticFile(t + "/" + ctx.remainingPathSegments.mkString("/")))
delegate(Map()).map(t =>
cask.model.StaticFile(t + "/" + ctx.remainingPathSegments.filter(s => s != "." && s != "..").mkString("/"))
)
}

def wrapPathSegment(s: String): Input = Seq(s)
Expand All @@ -24,7 +26,7 @@ class staticResources(val path: String, resourceRoot: ClassLoader = getClass.get
override def subpath = true
def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
delegate(Map()).map(t =>
cask.model.StaticResource(t + "/" + ctx.remainingPathSegments.mkString("/"), resourceRoot)
cask.model.StaticResource(t + "/" + ctx.remainingPathSegments.filter(s => s != "." && s != "..").mkString("/"), resourceRoot)
)
}

Expand Down
3 changes: 3 additions & 0 deletions example/staticFiles/app/src/StaticFiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ object StaticFiles extends cask.MainRoutes{
@cask.staticResources("/static/resource")
def staticResourceRoutes() = "cask"

@cask.staticResources("/static/resource2")
def staticResourceRoutes2() = "."

initialize()
}
5 changes: 5 additions & 0 deletions example/staticFiles/app/test/src/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ object ExampleTests extends TestSuite{

requests.get(s"$host/static/resource/example.txt").text() ==>
"the quick brown fox jumps over the lazy dog"

requests.get(s"$host/static/resource2/cask/example.txt").text() ==>
"the quick brown fox jumps over the lazy dog"

requests.get(s"$host/static/file/../../../build.sc").statusCode ==> 404
}

}
Expand Down

0 comments on commit ece16bb

Please sign in to comment.