Skip to content

Commit

Permalink
IPv4 address with mask should not contain a white space
Browse files Browse the repository at this point in the history
This IPv4 address should be illegal `0.0.0.0 /32`.  This is compatible
with `inet_net_pton`.
  • Loading branch information
coot committed Jul 11, 2024
1 parent b59eb35 commit 2601332
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Data/IP/Addr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ ip4' checkTermination = do
_ <- char '.'
a3 <- octet
let as = [a0, a1, a2, a3]
skipSpaces
when checkTermination termination
when checkTermination $
skipSpaces >> termination
return as

skipSpaces :: Parser ()
Expand Down
5 changes: 4 additions & 1 deletion test/IPSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ data InvalidIPv4Str = Iv4 String deriving (Show)

instance Arbitrary InvalidIPv4Str where
arbitrary =
frequency [(9, arbitraryIIPv4Str arbitrary 32)
frequency [(8, arbitraryIIPv4Str arbitrary 32)
-- an IPv4 address should not end with a trailing `.`
,(1, Iv4 . (++ ".") . show <$> genIPv4)
-- an IPv4 address with mask should not include a white space
,(1, (\ip (NonNegative len) -> Iv4 (show ip ++ " /" ++ show (len :: Integer))) <$> genIPv4 <*> arbitrary)
]
where
genIPv4 :: Gen IPv4
Expand Down

0 comments on commit 2601332

Please sign in to comment.