diff --git a/servant-docs/test/Servant/DocsSpec.hs b/servant-docs/test/Servant/DocsSpec.hs index 4d18f7e2..5c98ec32 100644 --- a/servant-docs/test/Servant/DocsSpec.hs +++ b/servant-docs/test/Servant/DocsSpec.hs @@ -22,8 +22,6 @@ import Control.Monad import Control.Monad.Trans.Writer (Writer, runWriter, tell) import Data.Aeson -import Data.Data - (Data) import Data.List (isInfixOf) import Data.Proxy @@ -161,7 +159,7 @@ spec = describe "Servant.Docs" $ do data Datatype1 = Datatype1 { dt1field1 :: String , dt1field2 :: Int - } deriving (Eq, Show, Data, Generic) + } deriving (Eq, Show, Generic) instance ToJSON Datatype1 instance ToForm Datatype1 diff --git a/servant-server/src/Servant/Server/Internal.hs b/servant-server/src/Servant/Server/Internal.hs index 988e4ecb..36f9f15e 100644 --- a/servant-server/src/Servant/Server/Internal.hs +++ b/servant-server/src/Servant/Server/Internal.hs @@ -607,7 +607,7 @@ instance mev :: Maybe (Either T.Text a) mev = case B.length rawQS of 0 -> Nothing - _ -> Just $ urlDecodeAsForm (BL.drop 1 . BL.fromStrict $ rawQS) + _ -> Just $ urlDecodeAsForm $ BL.drop 1 $ BL.fromStrict rawQS errReq = delayedFailFatal err400 { errBody = "Query parameter form is required" diff --git a/servant-server/test/Servant/ServerSpec.hs b/servant-server/test/Servant/ServerSpec.hs index e71c2015..265b2aa4 100644 --- a/servant-server/test/Servant/ServerSpec.hs +++ b/servant-server/test/Servant/ServerSpec.hs @@ -514,6 +514,15 @@ queryParamFormSpec = do } liftIO $ do decode' (simpleBody response1) `shouldBe` (Just $ Animal { species = "bimac", numberOfLegs = 7}) + it "Just a question mark will match but return a Left" $ + (flip runSession) (serve queryParamFormApi qpFormServer) $ do + let paramsQ = "?" + response1 <- Network.Wai.Test.request defaultRequest{ + rawQueryString = paramsQ, + queryString = parseQuery paramsQ + } + liftIO $ do + decode' (simpleBody response1) `shouldBe` (Just $ Animal { species = "broken", numberOfLegs = 0}) it "allows no query params at all" $ (flip runSession) (serve queryParamFormApi qpFormServer) $ do response1 <- Network.Wai.Test.request defaultRequest