make gemQuery field of GemURL optional (with Maybe)

This commit is contained in:
Jonathan Lamothe 2021-10-24 18:54:41 -04:00
parent a2d8f1a5ea
commit a5d0c25fc3
3 changed files with 10 additions and 7 deletions

View File

@ -53,8 +53,8 @@ encodeGemURL url =
Nothing -> ""
path = intercalate "/" $ map escapeString $ gemPath url
query = case gemQuery url of
"" -> ""
q -> '?' : escapeString q
Nothing -> ""
Just q -> '?' : escapeString q
-- | add required escape sequences to a string
escapeString :: String -> String

View File

@ -39,8 +39,8 @@ data GemURL = GemURL
-- ^ The port number (if supplied)
, gemPath :: [String]
-- ^ The decoded path segments
, gemQuery :: String
-- ^ The decoded request query
, gemQuery :: Maybe String
-- ^ The decoded request query (if supplied)
} deriving (Eq, Show)
-- | Builds a new 'GemURL'
@ -52,7 +52,7 @@ newGemURL host = GemURL
{ gemHost = host
, gemPort = Nothing
, gemPath = []
, gemQuery = ""
, gemQuery = Nothing
}
--jl

View File

@ -45,6 +45,7 @@ encodeGemURLSpec = describe "encodeGemURL" $ mapM_
, ( "with port", withPortURL, withPortExp )
, ( "with path", withPathURL, withPathExp )
, ( "with query", withQueryURL, withQueryExp )
, ( "blank query", blankQueryURL, blankQueryExp )
, ( "with escape", withEscapeURL, withEscapeExp )
]
@ -55,12 +56,14 @@ encodeGemURLSpec = describe "encodeGemURL" $ mapM_
withPortExp = "gemini://example.com:1965/"
withPathURL = simpleURL { gemPath = ["foo", "bar"] }
withPathExp = "gemini://example.com/foo/bar"
withQueryURL = simpleURL { gemQuery = "foo" }
withQueryURL = simpleURL { gemQuery = Just "foo" }
withQueryExp = "gemini://example.com/?foo"
blankQueryURL = simpleURL { gemQuery = Just "" }
blankQueryExp = "gemini://example.com/?"
withEscapeURL = simpleURL
{ gemPath = ["foo bar"]
, gemQuery = "baz quux"
, gemQuery = Just "baz quux"
}
withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"