make gemQuery field of GemURL optional (with Maybe)
This commit is contained in:
parent
a2d8f1a5ea
commit
a5d0c25fc3
|
@ -53,8 +53,8 @@ encodeGemURL url =
|
||||||
Nothing -> ""
|
Nothing -> ""
|
||||||
path = intercalate "/" $ map escapeString $ gemPath url
|
path = intercalate "/" $ map escapeString $ gemPath url
|
||||||
query = case gemQuery url of
|
query = case gemQuery url of
|
||||||
"" -> ""
|
Nothing -> ""
|
||||||
q -> '?' : escapeString q
|
Just q -> '?' : escapeString q
|
||||||
|
|
||||||
-- | add required escape sequences to a string
|
-- | add required escape sequences to a string
|
||||||
escapeString :: String -> String
|
escapeString :: String -> String
|
||||||
|
|
|
@ -39,8 +39,8 @@ data GemURL = GemURL
|
||||||
-- ^ The port number (if supplied)
|
-- ^ The port number (if supplied)
|
||||||
, gemPath :: [String]
|
, gemPath :: [String]
|
||||||
-- ^ The decoded path segments
|
-- ^ The decoded path segments
|
||||||
, gemQuery :: String
|
, gemQuery :: Maybe String
|
||||||
-- ^ The decoded request query
|
-- ^ The decoded request query (if supplied)
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
-- | Builds a new 'GemURL'
|
-- | Builds a new 'GemURL'
|
||||||
|
@ -52,7 +52,7 @@ newGemURL host = GemURL
|
||||||
{ gemHost = host
|
{ gemHost = host
|
||||||
, gemPort = Nothing
|
, gemPort = Nothing
|
||||||
, gemPath = []
|
, gemPath = []
|
||||||
, gemQuery = ""
|
, gemQuery = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
|
@ -45,6 +45,7 @@ encodeGemURLSpec = describe "encodeGemURL" $ mapM_
|
||||||
, ( "with port", withPortURL, withPortExp )
|
, ( "with port", withPortURL, withPortExp )
|
||||||
, ( "with path", withPathURL, withPathExp )
|
, ( "with path", withPathURL, withPathExp )
|
||||||
, ( "with query", withQueryURL, withQueryExp )
|
, ( "with query", withQueryURL, withQueryExp )
|
||||||
|
, ( "blank query", blankQueryURL, blankQueryExp )
|
||||||
, ( "with escape", withEscapeURL, withEscapeExp )
|
, ( "with escape", withEscapeURL, withEscapeExp )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -55,12 +56,14 @@ encodeGemURLSpec = describe "encodeGemURL" $ mapM_
|
||||||
withPortExp = "gemini://example.com:1965/"
|
withPortExp = "gemini://example.com:1965/"
|
||||||
withPathURL = simpleURL { gemPath = ["foo", "bar"] }
|
withPathURL = simpleURL { gemPath = ["foo", "bar"] }
|
||||||
withPathExp = "gemini://example.com/foo/bar"
|
withPathExp = "gemini://example.com/foo/bar"
|
||||||
withQueryURL = simpleURL { gemQuery = "foo" }
|
withQueryURL = simpleURL { gemQuery = Just "foo" }
|
||||||
withQueryExp = "gemini://example.com/?foo"
|
withQueryExp = "gemini://example.com/?foo"
|
||||||
|
blankQueryURL = simpleURL { gemQuery = Just "" }
|
||||||
|
blankQueryExp = "gemini://example.com/?"
|
||||||
|
|
||||||
withEscapeURL = simpleURL
|
withEscapeURL = simpleURL
|
||||||
{ gemPath = ["foo bar"]
|
{ gemPath = ["foo bar"]
|
||||||
, gemQuery = "baz quux"
|
, gemQuery = Just "baz quux"
|
||||||
}
|
}
|
||||||
|
|
||||||
withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"
|
withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user