git.iko.soy/typeable/http-api-data
on master help sign in
Fixed erroneous behavior when parsing faulty inputs.
commita0e325c5401735ada878aa843cfa2d2349372bf7 authorMomemtumMori <admin@momemtummori.info> dateWed 9 Jul 2014, 12:22 (12 years ago) parent54b0c62
1 file changed+10−11
Web/PathPieces.hs+10−11
Web/PathPieces.hs+10−11
@@ -10,7 +10,6 @@ module Web.PathPieces
1010 ) where
1111
1212import Data.Int (Int64)
13−import Data.Maybe (fromJust)
1413import qualified Data.Text as S
1514import qualified Data.Text.Lazy as L
1615import qualified Data.Text.Read
@@ -67,6 +66,16 @@ instance PathPiece Day where
6766 _ -> Nothing
6867 toPathPiece = S.pack . show
6968
69+instance (PathPiece a) => PathPiece (Maybe a) where
70+ fromPathPiece s = case S.stripPrefix "Just " s of
71+ Just r -> Just `fmap` fromPathPiece r
72+ _ -> case s of
73+ "Nothing" -> Just Nothing
74+ _ -> Nothing
75+ toPathPiece m = case m of
76+ Just s -> "Just " `S.append` toPathPiece s
77+ _ -> "Nothing"
78+
7079class PathMultiPiece s where
7180 fromPathMultiPiece :: [S.Text] -> Maybe s
7281 toPathMultiPiece :: s -> [S.Text]
@@ -83,16 +92,6 @@ instance PathMultiPiece [L.Text] where
8392 fromPathMultiPiece = Just . map (L.fromChunks . return)
8493 toPathMultiPiece = map $ S.concat . L.toChunks
8594
86−instance (PathPiece a) => PathPiece (Maybe a) where
87− fromPathPiece s = case S.stripPrefix "Just " s of
88− Just r -> Just $ fromPathPiece r
89− _ -> case s of
90− "Nothing" -> Just Nothing
91− _ -> Nothing
92− toPathPiece m = case m of
93− Just s -> "Just " `S.append` toPathPiece s
94− _ -> "Nothing"
95−
9695{-# DEPRECATED toSinglePiece "Use toPathPiece instead of toSinglePiece" #-}
9796toSinglePiece :: PathPiece p => p -> S.Text
9897toSinglePiece = toPathPiece