on master help sign in
Merge pull request #696 from edsko/pr/escape-capture

Make sure path components get escaped

commit018a38cc933db9f289ca701e9cc1a5d9963a6887 authorOleg Grenrus <oleg.grenrus@iki.fi> dateSun 14 May 2017, 21:01 (9 years ago) parent54c3053507f021
1 file changed+5−3
servant-client/src/Servant/Common/Req.hs+5−3
servant-client/src/Servant/Common/Req.hs+5−3
@@ -27,6 +27,7 @@ import Control.Monad.Base (MonadBase (..))
2727import Control.Monad.IO.Class ()
2828import Control.Monad.Reader
2929import Control.Monad.Trans.Control (MonadBaseControl (..))
30+import qualified Data.ByteString.Builder as BS
3031import Data.ByteString.Lazy hiding (pack, filter, map, null, elem, any)
3132import Data.String
3233import Data.String.Conversions (cs)
@@ -86,7 +87,7 @@ instance Eq ServantError where
8687instance Exception ServantError
8788
8889data Req = Req
89− { reqPath :: String
90+ { reqPath :: BS.Builder
9091 , qs :: QueryText
9192 , reqBody :: Maybe (RequestBody, MediaType)
9293 , reqAccept :: [MediaType]
@@ -98,7 +99,7 @@ defReq = Req "" [] Nothing [] []
9899
99100appendToPath :: String -> Req -> Req
100101appendToPath p req =
101− req { reqPath = reqPath req ++ "/" ++ p }
102+ req { reqPath = reqPath req <> "/" <> toEncodedUrlPiece p }
102103
103104appendToQueryString :: Text -- ^ param name
104105 -> Maybe Text -- ^ param value
@@ -151,8 +152,9 @@ reqToRequest req (BaseUrl reqScheme reqHost reqPort path) =
151152 , uriRegName = reqHost
152153 , uriPort = ":" ++ show reqPort
153154 }
154− , uriPath = path ++ reqPath req
155+ , uriPath = fullPath
155156 }
157+ fullPath = path ++ cs (BS.toLazyByteString (reqPath req))
156158
157159 setrqb r = case reqBody req of
158160 Nothing -> r