packages feed

dns-patterns 0.1.1 → 0.1.2

raw patch · 4 files changed

+66/−33 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.DNS.Pattern: foldCase :: Domain -> Domain
+ Network.DNS.Pattern: foldCaseLabel :: DomainLabel -> DomainLabel

Files

CHANGELOG.md view
@@ -7,3 +7,7 @@ ## 0.1.1 -- 2022-07-06  * Allow parseAbsDomainRelax for absolute domains++## 0.1.2 -- 2022-08-18++* Add 'foldCase' and 'foldCaseLabel'
dns-patterns.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               dns-patterns-version:            0.1.1+version:            0.1.2 author:             Victor Nawothnig maintainer:         Victor Nawothnig (dminuoso@icloud.com) copyright:          (c) 2022 Wobcom GmbH
lib/Network/DNS/Pattern.hs view
@@ -17,6 +17,8 @@   , DomainLabel(..)   , pprDomain   , pprDomainLabel+  , foldCase+  , foldCaseLabel    -- * Pattern language   -- $patterns@@ -113,38 +115,45 @@   deriving (Ord)  instance Eq DomainLabel where-  DomainLabel l == DomainLabel r =-        BS.map caseFold l == BS.map caseFold r-    where-        caseFold :: Word8 -> Word8-        caseFold x = case x of-            0x41 -> c2w 'a'-            0x42 -> c2w 'b'-            0x43 -> c2w 'c'-            0x44 -> c2w 'd'-            0x45 -> c2w 'e'-            0x46 -> c2w 'f'-            0x47 -> c2w 'g'-            0x48 -> c2w 'h'-            0x49 -> c2w 'i'-            0x4a -> c2w 'j'-            0x4b -> c2w 'k'-            0x4c -> c2w 'l'-            0x4d -> c2w 'm'-            0x4e -> c2w 'n'-            0x4f -> c2w 'o'-            0x50 -> c2w 'p'-            0x51 -> c2w 'q'-            0x52 -> c2w 'r'-            0x53 -> c2w 's'-            0x54 -> c2w 't'-            0x55 -> c2w 'u'-            0x56 -> c2w 'v'-            0x57 -> c2w 'w'-            0x58 -> c2w 'x'-            0x59 -> c2w 'y'-            0x5a -> c2w 'z'-            _    -> x+  DomainLabel l == DomainLabel r+    = BS.map foldCase_ l == BS.map foldCase_ r++foldCase :: Domain -> Domain+foldCase (Domain ls) = Domain (foldCaseLabel <$> ls)++-- | Case-folding according to [RFC4343](https://datatracker.ietf.org/doc/html/rfc4343#section-3).+foldCaseLabel :: DomainLabel -> DomainLabel+foldCaseLabel (DomainLabel l) = DomainLabel (BS.map foldCase_ l)++foldCase_ :: Word8 -> Word8+foldCase_ x = case x of+    0x41 -> c2w 'a'+    0x42 -> c2w 'b'+    0x43 -> c2w 'c'+    0x44 -> c2w 'd'+    0x45 -> c2w 'e'+    0x46 -> c2w 'f'+    0x47 -> c2w 'g'+    0x48 -> c2w 'h'+    0x49 -> c2w 'i'+    0x4a -> c2w 'j'+    0x4b -> c2w 'k'+    0x4c -> c2w 'l'+    0x4d -> c2w 'm'+    0x4e -> c2w 'n'+    0x4f -> c2w 'o'+    0x50 -> c2w 'p'+    0x51 -> c2w 'q'+    0x52 -> c2w 'r'+    0x53 -> c2w 's'+    0x54 -> c2w 't'+    0x55 -> c2w 'u'+    0x56 -> c2w 'v'+    0x57 -> c2w 'w'+    0x58 -> c2w 'x'+    0x59 -> c2w 'y'+    0x5a -> c2w 'z'+    _    -> x  -- | Print an arbitrary domain into a presentation format. --
test/Spec.hs view
@@ -34,12 +34,16 @@ instance Show DomainPattern where   showsPrec _ d = mappend (T.unpack (pprPattern d)) +instance Show DomainLabel where+  showsPrec _ d = mappend (T.unpack (pprDomainLabel d))+ main :: IO () main = do   runTestTTAndExit $ TestList     [ patternMatchSpecs     , patternParseSpecs     , equalitySpecs+    , caseFoldSpecs     , patternContainedSpecs     , pprRoundTrips     ]@@ -175,6 +179,22 @@                    pure (pprDomain r == input))    ]++caseFoldSpecs :: Test+caseFoldSpecs = TestList+  [ let d = "Foo.Bar." in+    TestCase $ assertEqual "t1" d (foldCase d)++  , let d = "foo.bar." in+    TestCase $ assertEqual "t2" d (foldCase d)++  , let d = "FOO.BAR." in+    TestCase $ assertEqual "t3" d (foldCase d)++  , let l = "Foo" in+    TestCase $ assertEqual "t4" l (foldCaseLabel l)+  ]+  patternMatchSpecs :: Test patternMatchSpecs = TestList