packages feed

web-routes 0.27.16 → 0.27.17

raw patch · 4 files changed

+147/−22 lines, 4 filesdep −ghc-primdep −utf8-stringPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: ghc-prim, utf8-string

API changes (from Hackage documentation)

+ Web.Routes.PathInfo: ($dmfromPathSegments) :: (PathInfo url, Generic url, GPathInfo (Rep url)) => URLParser url
+ Web.Routes.PathInfo: ($dmtoPathSegments) :: (PathInfo url, Generic url, GPathInfo (Rep url)) => url -> [Text]
+ Web.Routes.PathInfo: dropTrailingSlash :: ByteString -> ByteString
+ Web.Routes.PathInfo: dropTrailingSlashText :: Text -> Text
+ Web.Routes.PathInfo: fromPathInfoParamsText :: PathInfo url => Text -> Either String (url, [(Text, Maybe Text)])
+ Web.Routes.PathInfo: fromPathInfoText :: PathInfo url => Text -> Either String url
+ Web.Routes.PathInfo: toAbsolutePathInfo :: PathInfo url => url -> Text
+ Web.Routes.PathInfo: toAbsolutePathInfoParams :: PathInfo url => url -> [(Text, Maybe Text)] -> Text
- Web.Routes.PathInfo: class () => Generic a
+ Web.Routes.PathInfo: class Generic a
- Web.Routes.PathInfo: fromPathSegments :: (PathInfo url, Generic url, GPathInfo (Rep url)) => URLParser url
+ Web.Routes.PathInfo: fromPathSegments :: PathInfo url => URLParser url
- Web.Routes.PathInfo: toPathSegments :: (PathInfo url, Generic url, GPathInfo (Rep url)) => url -> [Text]
+ Web.Routes.PathInfo: toPathSegments :: PathInfo url => url -> [Text]
- Web.Routes.RouteT: RouteT :: ((url -> [(Text, Maybe Text)] -> Text) -> m a) -> RouteT url m a
+ Web.Routes.RouteT: RouteT :: ((url -> [(Text, Maybe Text)] -> Text) -> m a) -> RouteT url (m :: Type -> Type) a
- Web.Routes.RouteT: [unRouteT] :: RouteT url m a -> (url -> [(Text, Maybe Text)] -> Text) -> m a
+ Web.Routes.RouteT: [unRouteT] :: RouteT url (m :: Type -> Type) a -> (url -> [(Text, Maybe Text)] -> Text) -> m a
- Web.Routes.RouteT: askRouteT :: Monad m => RouteT url m (url -> [(Text, Maybe Text)] -> Text)
+ Web.Routes.RouteT: askRouteT :: forall (m :: Type -> Type) url. Monad m => RouteT url m (url -> [(Text, Maybe Text)] -> Text)
- Web.Routes.RouteT: class (Monad m) => MonadRoute m where {
+ Web.Routes.RouteT: class Monad m => MonadRoute (m :: Type -> Type) where {
- Web.Routes.RouteT: nestURL :: (url1 -> url2) -> RouteT url1 m a -> RouteT url2 m a
+ Web.Routes.RouteT: nestURL :: forall url1 url2 (m :: Type -> Type) a. (url1 -> url2) -> RouteT url1 m a -> RouteT url2 m a
- Web.Routes.RouteT: newtype RouteT url m a
+ Web.Routes.RouteT: newtype RouteT url (m :: Type -> Type) a
- Web.Routes.RouteT: type URL m;
+ Web.Routes.RouteT: type URL (m :: Type -> Type);
- Web.Routes.RouteT: withRouteT :: ((url' -> [(Text, Maybe Text)] -> Text) -> url -> [(Text, Maybe Text)] -> Text) -> RouteT url m a -> RouteT url' m a
+ Web.Routes.RouteT: withRouteT :: forall url' url (m :: Type -> Type) a. ((url' -> [(Text, Maybe Text)] -> Text) -> url -> [(Text, Maybe Text)] -> Text) -> RouteT url m a -> RouteT url' m a

Files

Web/Routes/Base.hs view
@@ -17,7 +17,6 @@        ) where  import Blaze.ByteString.Builder (Builder, toByteString)-import Codec.Binary.UTF8.String (encodeString, decodeString) import Data.ByteString          (ByteString) import Data.List                (intercalate, intersperse) import Data.Text                (Text)@@ -219,30 +218,48 @@ -}  {-|-Encodes a list of path segments into a valid URL fragment.+Encodes a list of path segments, and query string parameters, into a+valid URL fragment. -This function takes the following three steps:+This function takes the following steps:  * UTF-8 encodes the characters.  * Performs percent encoding on all unreserved characters, as well as \:\@\=\+\$, -* Intercalates with a slash.+* Prefixes each segment with a slash. +* Appends the query string, if there are parameters.+ For example: -> encodePathInfo [\"foo\", \"bar\", \"baz\"]+> encodePathInfo [\"foo\", \"bar\", \"baz\"] [] -\"foo\/bar\/baz\"+\"\/foo\/bar\/baz\" -> encodePathInfo [\"foo bar\", \"baz\/bin\"]+> encodePathInfo [\"foo bar\", \"baz\/bin\"] [] -\"foo\%20bar\/baz\%2Fbin\"+\"\/foo\%20bar\/baz\%2Fbin\" -> encodePathInfo [\"שלום\"]+> encodePathInfo [\"שלום\"] [] -\"%D7%A9%D7%9C%D7%95%D7%9D\"+\"\/%D7%A9%D7%9C%D7%95%D7%9D\" +> encodePathInfo [\"foo\"] [(\"q\", Just \"1\")]++\"\/foo?q=1\"++As each segment is prefixed with a slash, no segments (the root) is the+empty string, not a slash:++> encodePathInfo [] []++\"\"++> encodePathInfo [] [(\"q\", Just \"1\")]++\"?q=1\"+ -} encodePathInfo :: [Text] -> [(Text, Maybe Text)] -> Text encodePathInfo segments qs =@@ -263,11 +280,9 @@  * UTF-8 decodes the resulting data. -This utilizes 'decodeString' from the utf8-string library, and thus all UTF-8-decoding errors are handled as per that library.--In general, you will want to strip the leading slash from a pathinfo before-passing it to this function. For example:+This utilizes 'decodePathSegments' from the http-types library, and thus all+UTF-8 decoding errors are handled as per that library. A leading slash is+dropped; a trailing slash is a last, empty segment. For example:  > decodePathInfo \"\" @@ -275,9 +290,17 @@  > decodePathInfo \"\/\" -[\"\"]+\[\] -Note that while function accepts a 'Text' value, it is expected that 'Text' will only contain the subset of characters which are allowed to appear in a URL.+> decodePathInfo \"\/foo\/bar\"++[\"foo\",\"bar\"]++> decodePathInfo \"\/foo\/bar\/\"++[\"foo\",\"bar\",\"\"]++Note that while this function accepts a 'ByteString' value, it is expected that it will only contain the subset of characters which are allowed to appear in a URL. -} decodePathInfo :: ByteString -> [Text] decodePathInfo = decodePathSegments
Web/Routes/PathInfo.hs view
@@ -17,8 +17,14 @@     , PathInfo(..)     , toPathInfo     , toPathInfoParams+    , toAbsolutePathInfo+    , toAbsolutePathInfoParams     , fromPathInfo     , fromPathInfoParams+    , fromPathInfoText+    , fromPathInfoParamsText+    , dropTrailingSlash+    , dropTrailingSlashText     , mkSitePI     , showParseError #if __GLASGOW_HASKELL__ > 702@@ -35,7 +41,8 @@ import Data.Int (Int8, Int16, Int32, Int64) import Data.List as List (stripPrefix, tails) import Data.Text as Text (Text, pack, unpack, null, tails, stripPrefix)-import Data.Text.Encoding (decodeUtf8)+import qualified Data.Text as T+import Data.Text.Encoding (decodeUtf8, encodeUtf8) import Data.Text.Read (decimal, signed) import Data.Maybe (fromJust) import Data.Word (Word, Word8, Word16, Word32, Word64)@@ -266,6 +273,27 @@                  -> Text toPathInfoParams url params = encodePathInfo (toPathSegments url) params +-- | as 'toPathInfo', but an absolute path: a url with no path segments+-- (the root) is @\"\/\"@, where 'toPathInfo' gives @\"\"@ (which, as a+-- link, is the current page). Other urls are as 'toPathInfo' gives them.+toAbsolutePathInfo :: (PathInfo url) => url -> Text+toAbsolutePathInfo = absolutePath . toPathInfo++-- | as 'toPathInfoParams', but an absolute path: the root is+-- @\"\/\"@, and with parameters @\"\/?q=1\"@ (where+-- 'toPathInfoParams' gives @\"?q=1\"@)+toAbsolutePathInfoParams :: (PathInfo url) =>+                            url -- ^ url+                         -> [(Text, Maybe Text)] -- ^ query string parameter+                         -> Text+toAbsolutePathInfoParams url params = absolutePath (toPathInfoParams url params)++-- | a path info with a leading slash, if it has no path segments+absolutePath :: Text -> Text+absolutePath t+  | T.null t || T.pack "?" `T.isPrefixOf` t = T.cons '/' t+  | otherwise                               = t+ -- should this fail if not all the input was consumed? -- -- in theory we@@ -301,6 +329,36 @@   (,query) <$> parseSegments fromPathSegments url   where     (url, query) = decodePathInfoParams $ dropSlash pi++-- | as 'fromPathInfo', for a path info as 'Text' (which is UTF-8+-- encoded, as a URL is)+fromPathInfoText :: (PathInfo url) => Text -> Either String url+fromPathInfoText = fromPathInfo . encodeUtf8++-- | as 'fromPathInfoParams', for a path info as 'Text'+fromPathInfoParamsText :: (PathInfo url) => Text -> Either String (url, [(Text, Maybe Text)])+fromPathInfoParamsText = fromPathInfoParams . encodeUtf8++-- | Removes one slash at the end of the path (before the query string,+-- if there is one), unless the path is only a slash: so a url parses the+-- same with or without it. 'fromPathInfo' itself keeps it, as a last,+-- empty segment, since a site may give @\/foo@ and @\/foo\/@ different+-- meanings.+--+-- > dropTrailingSlash "/foo/bar/"      == "/foo/bar"+-- > dropTrailingSlash "/foo/bar/?q=1"  == "/foo/bar?q=1"+-- > dropTrailingSlash "/"              == "/"+-- > fromPathInfo (dropTrailingSlash pathInfo)+dropTrailingSlash :: ByteString -> ByteString+dropTrailingSlash s =+  let (path, query) = B.break (== '?') s+  in if B.length path > 1 && B.last path == '/' then B.init path `B.append` query else s++-- | 'dropTrailingSlash', for a path info as 'Text'+dropTrailingSlashText :: Text -> Text+dropTrailingSlashText s =+  let (path, query) = T.break (== '?') s+  in if T.length path > 1 && T.last path == '/' then T.init path `T.append` query else s  -- | Removes a leading slash, if it exists dropSlash :: ByteString -> ByteString
test/Test.hs view
@@ -50,6 +50,48 @@          Left _ -> return ()          url    -> assertFailure $ "expected a Left, but got: " ++ show url +-- the root: no path segments+root :: [Text]+root = []++case_toAbsolutePathInfo :: Assertion+case_toAbsolutePathInfo =+    do -- toPathInfo and toPathInfoParams are as they were: the root is ""+       toPathInfo root @?= ""+       toPathInfoParams root [("q",Just "1")] @?= "?q=1"+       -- the absolute versions give "/" for it, and the same for the rest+       toAbsolutePathInfo root @?= "/"+       toAbsolutePathInfoParams root [("q",Just "1")] @?= "/?q=1"+       toAbsolutePathInfo Home @?= "/home"+       toAbsolutePathInfoParams (Article 0) [("q",Just "1")] @?= "/article/0?q=1"++case_fromPathInfoText :: Assertion+case_fromPathInfoText =+    do fromPathInfoText "/home" @?= Right Home+       fromPathInfoText "/article/0" @?= Right (Article 0)+       fromPathInfoParamsText "/article/0?q=1&r=2" @?= Right (Article 0, [("q",Just "1"),("r",Just "2")])+       case fromPathInfoText "/" :: Either String Sitemap of+         Left _ -> return ()+         url    -> assertFailure $ "expected a Left, but got: " ++ show url++case_dropTrailingSlash :: Assertion+case_dropTrailingSlash =+    do -- fromPathInfo keeps a trailing slash, as a last, empty segment+       case fromPathInfo "/home/" :: Either String Sitemap of+         Left _ -> return ()+         url    -> assertFailure $ "expected a Left, but got: " ++ show url+       fromPathInfo (dropTrailingSlash "/home/") @?= Right Home+       fromPathInfoParams (dropTrailingSlash "/article/0/?q=1") @?= Right (Article 0, [("q",Just "1")])+       dropTrailingSlash "/home/" @?= "/home"+       dropTrailingSlash "/home/?q=1" @?= "/home?q=1"+       dropTrailingSlash "/home" @?= "/home"+       dropTrailingSlash "/" @?= "/"+       dropTrailingSlash "" @?= ""+       dropTrailingSlashText "/home/" @?= "/home"+       dropTrailingSlashText "/home/?q=1" @?= "/home?q=1"+       dropTrailingSlashText "/" @?= "/"+       fromPathInfoText (dropTrailingSlashText "/article/0/") @?= Right (Article 0)+ main :: IO () main = hspec $ do  prop "toPathInfo" case_toPathInfo@@ -57,3 +99,6 @@  prop "fromPathInfo" case_fromPathInfo  prop "fromPathInfoParams" case_fromPathInfoParams  prop "PathInfo_isomorphism" prop_PathInfo_isomorphism+ prop "toAbsolutePathInfo" case_toAbsolutePathInfo+ prop "fromPathInfoText" case_fromPathInfoText+ prop "dropTrailingSlash" case_dropTrailingSlash
web-routes.cabal view
@@ -1,5 +1,5 @@ Name:             web-routes-Version:          0.27.16+Version:          0.27.17 License:          BSD3 License-File:     LICENSE Author:           jeremy@seereason.com@@ -10,7 +10,7 @@ Homepage:         http://www.happstack.com/docs/crashcourse/index.html#web-routes Cabal-Version:    >= 1.10 Build-type:       Simple-tested-with:      GHC==8.0.2, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.5, GHC==9.4.8, GHC==9.6.4, GHC==9.8.1+tested-with:      GHC==8.0.2, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.5, GHC==9.4.8, GHC==9.6.4, GHC==9.8.1, GHC==9.10.3, GHC==9.12.4, GHC==9.14.1  test-suite Test   Default-Language : Haskell2010@@ -33,10 +33,9 @@                           http-types    >= 0.6  && < 0.13,                           mtl           >= 2.0  && < 2.4,                           text          >= 0.11 && < 2.2,-                          utf8-string   >= 0.3  && < 1.1,                           exceptions    >= 0.6.1 && < 0.11         if impl(ghc >= 7.2)-          Build-Depends:  ghc-prim, split+          Build-Depends:  split         Exposed-Modules:  Web.Routes                           Web.Routes.Base                           Web.Routes.PathInfo