diff --git a/src/Falco/RequestValue.fs b/src/Falco/RequestValue.fs index 8d83f24..3e35362 100644 --- a/src/Falco/RequestValue.fs +++ b/src/Falco/RequestValue.fs @@ -48,8 +48,7 @@ module RequestValue = acc let parseRequestPrimitive (x : string) = - let decoded = WebUtility.UrlDecode x - match decoded with + match x with | IsNullOrWhiteSpace _ -> RNull | IsTrue x | IsFalse x -> RBool x @@ -208,7 +207,7 @@ module RequestValue = let private routeKeyValues (route : RouteValueDictionary) = route |> Seq.map (fun kvp -> - kvp.Key, seq { Convert.ToString(kvp.Value, Globalization.CultureInfo.InvariantCulture) }) + kvp.Key, seq { Convert.ToString(kvp.Value, Globalization.CultureInfo.InvariantCulture) |> WebUtility.UrlDecode }) let private queryKeyValues (query : IQueryCollection) = query diff --git a/test/Falco.IntegrationTests.App/Program.fs b/test/Falco.IntegrationTests.App/Program.fs index e2f1d80..abd355f 100644 --- a/test/Falco.IntegrationTests.App/Program.fs +++ b/test/Falco.IntegrationTests.App/Program.fs @@ -54,6 +54,20 @@ let endpoints = mapPost "/hello/{name?}" mapRouteData (fun person -> Request.mapForm (mapRequestData person) Response.ofJson) + get "/hello-query" + ( + Request.mapQuery + (fun r -> + let name = r?name.AsStringNonEmpty("world") + $"Hello {name}!") Response.ofPlainText) + + post "/hello-form" + ( + Request.mapForm + (fun r -> + let name = r?name.AsStringNonEmpty("world") + $"Hello {name}!") Response.ofPlainText) + mapGet "/plug/{name?}" (fun r -> r?name.AsStringNonEmpty("world")) (fun name ctx -> diff --git a/test/Falco.IntegrationTests/Program.fs b/test/Falco.IntegrationTests/Program.fs index cd77307..8ad049e 100644 --- a/test/Falco.IntegrationTests/Program.fs +++ b/test/Falco.IntegrationTests/Program.fs @@ -57,11 +57,30 @@ module Tests = let content = response.Content.ReadAsStringAsync().Result Assert.Equal("""{"Message":"Hello John!"}""", content) + let response = client.PostAsync("/hello/John+Smith", form).Result + let content = response.Content.ReadAsStringAsync().Result + Assert.Equal("""{"Message":"Hello John Smith!"}""", content) + use form = new FormUrlEncodedContent(dict [ ("age", "42") ]) let response = client.PostAsync("/hello/John", form).Result let content = response.Content.ReadAsStringAsync().Result Assert.Equal("""{"Message":"Hello John, you are 42 years old!"}""", content) + [] + let ``Receive mapped form response from: POST /hello-form`` () = + use client = factory.CreateClient () + use form = new FormUrlEncodedContent(dict [("name", "Mr ++ ")]) + let response = client.PostAsync("/hello-form", form).Result + let content = response.Content.ReadAsStringAsync().Result + Assert.Equal("Hello Mr ++ !", content) + + [] + let ``Receive mapped query response from: GET /hello-query`` () = + use client = factory.CreateClient () + let response = client.GetAsync("/hello-query?name=Mr%20%2B%2B").Result + let content = response.Content.ReadAsStringAsync().Result + Assert.Equal("Hello Mr ++!", content) + [] let ``Receive utf8 text/plain response from: GET /plug/name?`` () = use client = factory.CreateClient ()