escape characters in URLs
This commit is contained in:
parent
8590219126
commit
3484fda01e
|
@ -42,10 +42,10 @@ encodeRequest req =
|
||||||
authority = reqHost req ++ case reqPort req of
|
authority = reqHost req ++ case reqPort req of
|
||||||
Just port -> ':' : show port
|
Just port -> ':' : show port
|
||||||
Nothing -> ""
|
Nothing -> ""
|
||||||
path = intercalate "/" $ reqPath req
|
path = intercalate "/" $ map escapeString $ reqPath req
|
||||||
query = case reqQuery req of
|
query = case reqQuery req of
|
||||||
"" -> ""
|
"" -> ""
|
||||||
q -> '?' : q
|
q -> '?' : escapeString q
|
||||||
|
|
||||||
-- | add required escape sequences to a string
|
-- | add required escape sequences to a string
|
||||||
escapeString :: String -> String
|
escapeString :: String -> String
|
||||||
|
|
|
@ -44,6 +44,7 @@ encodeRequestSpec = describe "encodeRequest" $ mapM_
|
||||||
, ( "with port", withPortReq, withPortExp )
|
, ( "with port", withPortReq, withPortExp )
|
||||||
, ( "with path", withPathReq, withPathExp )
|
, ( "with path", withPathReq, withPathExp )
|
||||||
, ( "with query", withQueryReq, withQueryExp )
|
, ( "with query", withQueryReq, withQueryExp )
|
||||||
|
, ( "with escape", withEscapeReq, withEscapeExp )
|
||||||
]
|
]
|
||||||
|
|
||||||
where
|
where
|
||||||
|
@ -56,6 +57,13 @@ encodeRequestSpec = describe "encodeRequest" $ mapM_
|
||||||
withQueryReq = simpleReq { reqQuery = "foo" }
|
withQueryReq = simpleReq { reqQuery = "foo" }
|
||||||
withQueryExp = "gemini://example.com/?foo"
|
withQueryExp = "gemini://example.com/?foo"
|
||||||
|
|
||||||
|
withEscapeReq = simpleReq
|
||||||
|
{ reqPath = ["foo bar"]
|
||||||
|
, reqQuery = "baz quux"
|
||||||
|
}
|
||||||
|
|
||||||
|
withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"
|
||||||
|
|
||||||
escapeStringSpec :: Spec
|
escapeStringSpec :: Spec
|
||||||
escapeStringSpec = describe "escapeString" $ mapM_
|
escapeStringSpec = describe "escapeString" $ mapM_
|
||||||
( \(input, expected) -> context (show input) $
|
( \(input, expected) -> context (show input) $
|
||||||
|
|
Loading…
Reference in New Issue
Block a user