com-lihaoyi / cask

Cask: a Scala HTTP micro-framework. Cask makes it easy to set up a website, backend server, or REST API using Scala
https://com-lihaoyi.github.io/cask/
Other
525 stars 55 forks source link

Routes containing url-encoded parameters do not work as expected. #105

Closed jrlemieux closed 8 months ago

jrlemieux commented 8 months ago

I had a route defined by a pattern such as

/a/b/:paramA/:paramB

If the provided url is url-encoded (as it should), the route won't work if the parameter receive data with special characters. For example, to pass "hello world" and "1 + 1 = 2" in paramA and paramB, respectively, the url could be:

/a/b/hello+world/1+%2B+1+%3D+2

The methods defining the routes here receive the data non-decoded, i.e. "hello+world" is received in the parameter rather than "hello world".

The static files having a pattern with parameters containing special characters also do not work, and I suppose that it is related to the same issue.

Here is a test:

  @cask.get("/delete/:encoded_identification")
  def deleteGet(encoded_identification: String): Text.all.doctype =
    println(s"deleteGet, encoded_identification = '$encoded_identification'")

Query (here the + means a space):

http://localhost:6569/delete/toto+2

Result:

deleteGet, encoded_identification = 'toto+2'