modern-uri 0.3.3.1 → 0.3.4.0
raw patch · 5 files changed
+39/−23 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−0
- Text/URI/Render.hs +18/−12
- Text/URI/Types.hs +2/−1
- modern-uri.cabal +1/−1
- tests/Text/URISpec.hs +13/−9
CHANGELOG.md view
@@ -1,3 +1,8 @@+## Modern URI 0.3.4.0++* URIs with authority component and without path are now rendered without+ trailing slashes.+ ## Modern URI 0.3.3.1 * Works with `bytestring-0.11`.
Text/URI/Render.hs view
@@ -138,11 +138,12 @@ Tagged s b genericRender :: Render URI b-genericRender uri@URI {..} =+genericRender URI {..} = mconcat [ rJust rScheme uriScheme, rJust rAuthority (either (const Nothing) Just uriAuthority),- rPath (isPathAbsolute uri) uriPath,+ rAbsPathSlash uriAuthority uriPath,+ rPath uriPath, rQuery uriQuery, rJust rFragment uriFragment ]@@ -174,16 +175,21 @@ ] {-# INLINE rUserInfo #-} -rPath :: Bool -> Render (Maybe (Bool, NonEmpty (RText 'PathPiece))) b-rPath isAbsolute path = leading <> other- where- leading = if isAbsolute then "/" else mempty- other =- case path of- Nothing -> mempty- Just (trailingSlash, ps) ->- (mconcat . intersperse "/" . fmap renderText . NE.toList) ps- <> if trailingSlash then "/" else mempty+rAbsPathSlash ::+ Either Bool a ->+ Render (Maybe (Bool, NonEmpty (RText 'PathPiece))) b+rAbsPathSlash (Left isAbsolute) _ = if isAbsolute then "/" else mempty+rAbsPathSlash (Right _) Nothing = mempty+rAbsPathSlash (Right _) (Just _) = "/"+{-# INLINE rAbsPathSlash #-}++rPath :: Render (Maybe (Bool, NonEmpty (RText 'PathPiece))) b+rPath path =+ case path of+ Nothing -> mempty+ Just (trailingSlash, ps) ->+ (mconcat . intersperse "/" . fmap renderText . NE.toList) ps+ <> if trailingSlash then "/" else mempty {-# INLINE rPath #-} rQuery :: Render [QueryParam] b
Text/URI/Types.hs view
@@ -57,6 +57,7 @@ import Data.ByteString (ByteString) import Data.Char import Data.Data (Data)+import Data.Either (fromLeft) import Data.List (intercalate) import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE@@ -142,7 +143,7 @@ -- -- @since 0.1.0.0 isPathAbsolute :: URI -> Bool-isPathAbsolute = either id (const True) . uriAuthority+isPathAbsolute = fromLeft True . uriAuthority -- | Authority component of 'URI'. data Authority = Authority
modern-uri.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: modern-uri-version: 0.3.3.1+version: 0.3.4.0 license: BSD3 license-file: LICENSE.md maintainer: Mark Karpov <markkarpov92@gmail.com>
tests/Text/URISpec.hs view
@@ -265,15 +265,19 @@ (URI.render <$> URI.mkURI "//host/fir:st/se:cond") `shouldReturn` "//host/fir%3ast/se%3acond" context "when URI is a relative-path reference" $- it "escapes colon but only in the first path segment" $- do- firstSeg <- URI.mkPathPiece "fir:st"- secondSeg <- URI.mkPathPiece "se:cond"- let uri =- URI.emptyURI- { uriPath = Just (False, firstSeg :| [secondSeg])- }- URI.render uri `shouldBe` "fir%3ast/se%3acond"+ it "escapes colon but only in the first path segment" $ do+ firstSeg <- URI.mkPathPiece "fir:st"+ secondSeg <- URI.mkPathPiece "se:cond"+ let uri =+ URI.emptyURI+ { uriPath = Just (False, firstSeg :| [secondSeg])+ }+ URI.render uri `shouldBe` "fir%3ast/se%3acond"+ context "when URI has no path" $+ it "is rendered without trailing slash" $ do+ let uriWithoutSlash = "https://example.com"+ uri <- URI.mkURI uriWithoutSlash+ URI.render uri `shouldBe` uriWithoutSlash describe "renderBs" $ it "sort of works" $ fmap URI.renderBs mkTestURI `shouldReturn` testURI