You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
When using anyParams, it is impossible to reject malformed optional form fields; it unconditionally falls back to the query param, which is missing but optional, and therefor valid.
I.e:
// Passes as expected"anyParam directive" should "reject malformed optional query parameters" in {
Post("/?foo=bar", FormData(Seq.empty)) ~> anyParams('foo.as[Option[Int]]) {
foo => complete(s"foo: $foo")
} ~> check {
rejections.head shouldBe a [MalformedQueryParamRejection]
}
}
// Fails!
it should "reject malformed optional form fields" in {
Post("/", FormData(Seq("foo"->"bar"))) ~> anyParams('foo.as[Option[Int]]) {
foo => complete(s"foo: $foo")
} ~> check {
rejections.head shouldBe a [MalformedFormFieldRejection]
}
}
The second test fails:
...
[info] - should reject malformed optional form fields *** FAILED *** (8 milliseconds)
[info] Request was not rejected, response was HttpResponse(200 OK,HttpEntity(text/plain; charset=UTF-8,foo: None),List(),HTTP/1.1)
...
This behaviour is unexpected. It seems anyParams ought to fall back to query params only on missing form fields. (Or anyParams ought to be renamed any*Valid*Params, if you get my drift.)