attoparsec-uri 0.0.6 → 0.0.7
raw patch · 3 files changed
+38/−9 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.URI: URI :: !(Maybe Text) -> !Bool -> !URIAuth -> !(Maybe (Vector Text)) -> !(Vector (Pair Text (Maybe Text))) -> !(Maybe Text) -> URI
+ Data.URI: URI :: !Maybe Text -> !Bool -> !URIAuth -> !Maybe (Vector Text) -> !Vector (Pair Text (Maybe Text)) -> !Maybe Text -> URI
- Data.URI: [uriFragment] :: URI -> !(Maybe Text)
+ Data.URI: [uriFragment] :: URI -> !Maybe Text
- Data.URI: [uriPath] :: URI -> !(Maybe (Vector Text))
+ Data.URI: [uriPath] :: URI -> !Maybe (Vector Text)
- Data.URI: [uriQuery] :: URI -> !(Vector (Pair Text (Maybe Text)))
+ Data.URI: [uriQuery] :: URI -> !Vector (Pair Text (Maybe Text))
- Data.URI: [uriScheme] :: URI -> !(Maybe Text)
+ Data.URI: [uriScheme] :: URI -> !Maybe Text
- Data.URI.Auth: URIAuth :: !(Maybe Text) -> !URIAuthHost -> !(Maybe Word16) -> URIAuth
+ Data.URI.Auth: URIAuth :: !Maybe (Pair Text (Maybe Text)) -> !URIAuthHost -> !Maybe Word16 -> URIAuth
- Data.URI.Auth: [uriAuthPort] :: URIAuth -> !(Maybe Word16)
+ Data.URI.Auth: [uriAuthPort] :: URIAuth -> !Maybe Word16
- Data.URI.Auth: [uriAuthUser] :: URIAuth -> !(Maybe Text)
+ Data.URI.Auth: [uriAuthUser] :: URIAuth -> !Maybe (Pair Text (Maybe Text))
- Data.URI.Auth.Host: Host :: !(Vector Text) -> !Text -> URIAuthHost
+ Data.URI.Auth.Host: Host :: !Vector Text -> !Text -> URIAuthHost
- Data.URI.Auth.Host: [uriAuthHostName] :: URIAuthHost -> !(Vector Text)
+ Data.URI.Auth.Host: [uriAuthHostName] :: URIAuthHost -> !Vector Text
Files
- attoparsec-uri.cabal +2/−2
- src/Data/URI/Auth.hs +15/−4
- test/Spec.hs +21/−3
attoparsec-uri.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 14d2e305af1ea4cf74aa951aea3d3b29c0a5ee76135b2ec915c0c7e5858fc73e+-- hash: 4c6880fda99def0e3d086d09406f42a8fc03255b7dd64eb76559e6a62a49060f name: attoparsec-uri-version: 0.0.6+version: 0.0.7 synopsis: URI parser / printer using attoparsec description: Please see the README on GitHub at <https://github.com/githubuser/purescript-iso#readme> category: Web
src/Data/URI/Auth.hs view
@@ -12,6 +12,7 @@ import Prelude hiding (Maybe (..), maybe) import qualified Prelude as P import Data.Strict.Maybe (Maybe (..), maybe)+import Data.Strict.Tuple (Pair (..)) import Data.Text (Text) import Data.Word (Word16) import qualified Data.Text as T@@ -27,7 +28,7 @@ data URIAuth = URIAuth- { uriAuthUser :: !(Maybe Text) -- ^ a designated user - @ssh://git\@github.com@ is @git@+ { uriAuthUser :: !(Maybe (Pair Text (Maybe Text))) -- ^ a designated user - @ssh://git:foo\@github.com@ is @Just ("git" :!: Just "foo")@ , uriAuthHost :: !URIAuthHost , uriAuthPort :: !(Maybe Word16) -- ^ the port, if it exists - @foobar.com:3000@ is @3000@ as a 16-bit unsigned int. } deriving (Show, Eq, Typeable, Generic)@@ -35,14 +36,19 @@ instance Arbitrary URIAuth where arbitrary = URIAuth <$> arbitraryUser <*> arbitrary <*> arbitraryPort where- arbitraryUser = oneof [pure Nothing, Just <$> arbitraryNonEmptyText]+ arbitraryUser = oneof+ [ pure Nothing+ , do u <- arbitraryNonEmptyText+ mp <- oneof [pure Nothing] -- , Just <$> arbitraryNonEmptyText]+ pure $ Just $ u :!: mp+ ] arbitraryPort = oneof [pure Nothing, Just <$> arbitrary] arbitraryNonEmptyText = T.pack <$> listOf1 (elements ['a' .. 'z']) printURIAuth :: URIAuth -> Text printURIAuth URIAuth{..} =- maybe "" (<> "@") uriAuthUser+ maybe "" (\(u :!: mp) -> u <> maybe "" (":" <>) mp <> "@") uriAuthUser <> printURIAuthHost uriAuthHost <> maybe "" (\p -> ":" <> T.pack (show p)) uriAuthPort @@ -55,8 +61,13 @@ where parseUser = do u <- takeWhile1 (\c -> c `notElem` ['@','.',':','/','?','&','=']) <?> "user value"+ p <-+ let withPass = do+ _ <- char ':'+ takeWhile1 (\c -> c `notElem` ['@','.',':','/','?','&','=']) <?> "password value"+ in toStrictMaybe <$> optional withPass void (char '@') <?> "user @"- pure u+ pure (u :!: p) parsePort = do void (char ':') <?> "port delimiter" decimal
test/Spec.hs view
@@ -3,10 +3,12 @@ import Data.URI (printURI, parseURI) import Data.Text (Text)+import qualified Data.Text as T import Data.Attoparsec.Text (Parser, parseOnly) import Test.Tasty (testGroup, defaultMain) import qualified Test.Tasty.QuickCheck as Q import Test.QuickCheck.Property (Result, succeeded, failed)+import System.IO.Unsafe (unsafePerformIO) @@ -18,9 +20,25 @@ ] -parsePrintIso :: Eq a => (a -> Text) -> Parser a -> a -> Result+parsePrintIso :: Eq a => Show a => (a -> Text) -> Parser a -> a -> Result parsePrintIso print' parser x = case parseOnly parser (print' x) of- Left _ -> failed+ Left e ->+ let go = unsafePerformIO $ do+ putStr "Original value: "+ print x+ putStr "Printed Text: "+ putStrLn $ T.unpack $ print' x+ putStr "Parse Error: "+ print e+ in seq go failed Right y | y == x -> succeeded- | otherwise -> failed+ | otherwise ->+ let go = unsafePerformIO $ do+ putStr "Original value: "+ print x+ putStr "Printed Text: "+ putStrLn $ T.unpack $ print' x+ putStr "Parsed Value: "+ print y+ in seq go failed