git.iko.soy/typeable/servant-reflex
on master help sign in
Escape all path pieces and query parameters
1cf61d3Greg Hale
changelog.md+15
@@ -1,3 +1,18 @@
1+0.3.3
2+-----
3+
4+Explicitly escape reserved characters from path pieces and query parameters
5+
6+
7+0.3.2
8+-----
9+
10+- **Addition of 'Servant.Reflex.Common.Req.ClientOpts'** which
11+allows the users to apply a final adjustment to Requests before
12+thery are sent, such as setting the 'withCredentials' flag
13+or print the Request to the console for debugging
14+[PR #47](https://github.com/imalsogreg/servant-reflex/pull/47)
15+
10.3
160.3
2---
17---
3
18
servant-reflex.cabal+1−1
@@ -1,5 +1,5 @@
1Name: servant-reflex
1Name: servant-reflex
2−Version: 0.3.2
2+Version: 0.3.3
3Synopsis: Servant reflex API generator
3Synopsis: Servant reflex API generator
4Description: Servant reflex API generator
4Description: Servant reflex API generator
5License: BSD3
5License: BSD3
src/Servant/Common/Req.hs+8−2
@@ -28,6 +28,7 @@ import qualified Data.Text as T
28import qualified Data.Text.Encoding as TE
28import qualified Data.Text.Encoding as TE
29import Data.Traversable (forM)
29import Data.Traversable (forM)
30import Language.Javascript.JSaddle.Monad (JSM, MonadJSM)
30import Language.Javascript.JSaddle.Monad (JSM, MonadJSM)
31+import qualified Network.URI as N
31import Reflex.Dom hiding (tag)
32import Reflex.Dom hiding (tag)
32import Servant.Common.BaseUrl (BaseUrl, showBaseUrl,
33import Servant.Common.BaseUrl (BaseUrl, showBaseUrl,
33 SupportsServantReflex)
34 SupportsServantReflex)
@@ -170,7 +171,7 @@ reqToReflexRequest reqMeth reqHost req =
170
171
171 urlPath :: Dynamic t (Either Text Text)
172 urlPath :: Dynamic t (Either Text Text)
172 urlPath = (fmap.fmap)
173 urlPath = (fmap.fmap)
173− (T.intercalate "/" . fmap (builderToText . toEncodedUrlPiece))
174+ (T.intercalate "/" . fmap escape)
174 urlParts
175 urlParts
175
176
176 queryPartString :: (Text, QueryPart t) -> Dynamic t (Maybe (Either Text Text))
177 queryPartString :: (Text, QueryPart t) -> Dynamic t (Maybe (Either Text Text))
@@ -182,7 +183,9 @@ reqToReflexRequest reqMeth reqHost req =
182 QueryPartParams ps -> ffor ps $ \pStrings ->
183 QueryPartParams ps -> ffor ps $ \pStrings ->
183 if null pStrings
184 if null pStrings
184 then Nothing
185 then Nothing
186+ else Just . Right
187+ . T.intercalate "&"
185− else Just $ Right (T.intercalate "&" (fmap (\p -> pName <> "=" <> p) pStrings))
188+ $ fmap (\p -> pName <> "=" <> escape p) pStrings
186 QueryPartFlag fl -> ffor fl $ \case
189 QueryPartFlag fl -> ffor fl $ \case
187 True -> Just $ Right pName
190 True -> Just $ Right pName
188 False -> Nothing
191 False -> Nothing
@@ -400,3 +403,6 @@ fmapL f (Left e) = Left (f e)
400
403
401builderToText :: Builder.Builder -> T.Text
404builderToText :: Builder.Builder -> T.Text
402builderToText = TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString
405builderToText = TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString
406+
407+escape :: T.Text -> T.Text
408+escape = T.pack . N.escapeURIString (not . N.isReserved) . T.unpack . TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString . toEncodedUrlPiece