Skip to content

Commit 6ba12e0

Browse files
committed
Add failing test case to demonstrate query param issue
1 parent 79a29b0 commit 6ba12e0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

servant-client/test/Servant/ClientTestUtils.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ type Api =
134134
:<|> "captureAll" :> CaptureAll "names" String :> Get '[JSON] [Person]
135135
:<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person
136136
:<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person
137+
:<|> "param-echo" :> QueryParam "payload" String :> Get '[JSON] (Maybe String)
137138
-- This endpoint makes use of a 'Raw' server because it is not currently
138139
-- possible to handle arbitrary binary query param values with
139140
-- @servant-server@
@@ -175,6 +176,7 @@ getCapture :: String -> ClientM Person
175176
getCaptureAll :: [String] -> ClientM [Person]
176177
getBody :: Person -> ClientM Person
177178
getQueryParam :: Maybe String -> ClientM Person
179+
getQueryParamEcho :: Maybe String -> ClientM (Maybe String)
178180
getQueryParamBinary :: Maybe UrlEncodedByteString -> HTTP.Method -> ClientM Response
179181
getQueryParams :: [String] -> ClientM [Person]
180182
getQueryFlag :: Bool -> ClientM Bool
@@ -203,6 +205,7 @@ getRoot
203205
:<|> getCaptureAll
204206
:<|> getBody
205207
:<|> getQueryParam
208+
:<|> getQueryParamEcho
206209
:<|> getQueryParamBinary
207210
:<|> getQueryParams
208211
:<|> getQueryFlag
@@ -235,6 +238,7 @@ server = serve api (
235238
Just "alice" -> return alice
236239
Just n -> throwError $ ServerError 400 (n ++ " not found") "" []
237240
Nothing -> throwError $ ServerError 400 "missing parameter" "" [])
241+
:<|> return
238242
:<|> const (Tagged $ \request respond ->
239243
respond . maybe (Wai.responseLBS HTTP.notFound404 [] "Missing: payload")
240244
(Wai.responseLBS HTTP.ok200 [] . LazyByteString.fromStrict)

servant-client/test/Servant/SuccessSpec.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
101101
Left (FailureResponse _ r) <- runClient (getQueryParam (Just "bob")) baseUrl
102102
responseStatusCode r `shouldBe` HTTP.Status 400 "bob not found"
103103

104+
it "Servant.API.QueryParam echo special chars" $ \(_, baseUrl) -> do
105+
let payload = Just ":@&=+$,"
106+
left show <$> runClient (getQueryParamEcho payload) baseUrl `shouldReturn` Right payload
107+
104108
it "Servant.API.QueryParam binary data" $ \(_, baseUrl) -> do
105109
let payload = BS.pack [0, 1, 2, 4, 8, 16, 32, 64, 128]
106110
apiCall = getQueryParamBinary (Just $ UrlEncodedByteString payload) HTTP.methodGet

0 commit comments

Comments
 (0)