diff --git a/src/Servant/API/QueryParam.hs b/src/Servant/API/QueryParam.hs index ea6e3087..55f84b5d 100644 --- a/src/Servant/API/QueryParam.hs +++ b/src/Servant/API/QueryParam.hs @@ -132,12 +132,15 @@ instance (KnownSymbol sym, HasServer sublayout) route Proxy subserver request respond = do let querytext = parseQueryText $ rawQueryString request param = case lookup paramname querytext of - Just Nothing -> True -- param is there, with no value - _ -> False -- param not in the query string or with a value + Just Nothing -> True -- param is there, with no value + Just (Just v) -> examine v -- param with a value + Nothing -> False -- param not in the query string route (Proxy :: Proxy sublayout) (subserver param) request respond where paramname = cs $ symbolVal (Proxy :: Proxy sym) + examine v | v == "true" || v == "1" || v == "" = True + | otherwise = False instance (KnownSymbol sym, HasClient sublayout) => HasClient (QueryFlag sym :> sublayout) where diff --git a/test/Servant/ServerSpec.hs b/test/Servant/ServerSpec.hs index 07897889..38313136 100644 --- a/test/Servant/ServerSpec.hs +++ b/test/Servant/ServerSpec.hs @@ -178,6 +178,17 @@ queryParamSpec = do name = "ALICE" } + let params3' = "?capitalize=" + response3' <- Network.Wai.Test.request defaultRequest{ + rawQueryString = params3', + queryString = parseQuery params3', + pathInfo = ["b"] + } + liftIO $ + decode' (simpleBody response3') `shouldBe` Just alice{ + name = "ALICE" + } + type PostApi = ReqBody Person :> Post Integer postApi :: Proxy PostApi postApi = Proxy