git.iko.soy/typeable/servant
on master help sign in
make QueryFlag more permissive
commit080222178997f1c8b125126ebc021bf4e4d202cc authorAlp Mestanogullari <alpmestan@gmail.com> dateFri 31 Oct 2014, 13:01 (12 years ago) parenta9eeff1
2 files changed+16−2
src/Servant/API/QueryParam.hs+5−2 test/Servant/ServerSpec.hs+11
src/Servant/API/QueryParam.hs+5−2
@@ -132,12 +132,15 @@ instance (KnownSymbol sym, HasServer sublayout)
132132 route Proxy subserver request respond = do
133133 let querytext = parseQueryText $ rawQueryString request
134134 param = case lookup paramname querytext of
135− Just Nothing -> True -- param is there, with no value
136− _ -> False -- param not in the query string or with a value
135+ Just Nothing -> True -- param is there, with no value
136+ Just (Just v) -> examine v -- param with a value
137+ Nothing -> False -- param not in the query string
137138
138139 route (Proxy :: Proxy sublayout) (subserver param) request respond
139140
140141 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
142+ examine v | v == "true" || v == "1" || v == "" = True
143+ | otherwise = False
141144
142145instance (KnownSymbol sym, HasClient sublayout)
143146 => HasClient (QueryFlag sym :> sublayout) where
test/Servant/ServerSpec.hs+11
@@ -178,6 +178,17 @@ queryParamSpec = do
178178 name = "ALICE"
179179 }
180180
181+ let params3' = "?capitalize="
182+ response3' <- Network.Wai.Test.request defaultRequest{
183+ rawQueryString = params3',
184+ queryString = parseQuery params3',
185+ pathInfo = ["b"]
186+ }
187+ liftIO $
188+ decode' (simpleBody response3') `shouldBe` Just alice{
189+ name = "ALICE"
190+ }
191+
181192type PostApi = ReqBody Person :> Post Integer
182193postApi :: Proxy PostApi
183194postApi = Proxy