Domain Parser: return the last point.
This commit is contained in:
parent
91337d0f57
commit
26b1c59937
@ -34,11 +34,15 @@ domain = PC.try (string " ") <|> sub_eof
|
|||||||
sub_eof :: Parser String String
|
sub_eof :: Parser String String
|
||||||
sub_eof = do
|
sub_eof = do
|
||||||
sub <- subdomain
|
sub <- subdomain
|
||||||
PC.optional (char '.')
|
maybe_final_point <- PC.optionMaybe (char '.')
|
||||||
eof
|
eof
|
||||||
if S.length sub > 255
|
let parsed_domain = did_we_parsed_the_final_point maybe_final_point sub
|
||||||
then fail $ "domain length is > 255 bytes (" <> show (S.length sub) <> ")"
|
if S.length parsed_domain > 255
|
||||||
else pure sub
|
then fail $ "domain length is > 255 bytes (" <> show (S.length parsed_domain) <> ")"
|
||||||
|
else pure parsed_domain
|
||||||
|
where
|
||||||
|
did_we_parsed_the_final_point Nothing sub = sub
|
||||||
|
did_we_parsed_the_final_point (Just _) sub = sub <> "."
|
||||||
|
|
||||||
-- From RFC 1035: <subdomain> ::= <label> | <subdomain> "." <label>
|
-- From RFC 1035: <subdomain> ::= <label> | <subdomain> "." <label>
|
||||||
subdomain :: Parser String String
|
subdomain :: Parser String String
|
||||||
@ -46,7 +50,7 @@ subdomain = do
|
|||||||
-- First: read a label. This is bare minimum for a subdomain.
|
-- First: read a label. This is bare minimum for a subdomain.
|
||||||
lab <- label
|
lab <- label
|
||||||
-- Second: the rest is optional.
|
-- Second: the rest is optional.
|
||||||
r <- PC.optionMaybe point_sub
|
r <- PC.optionMaybe (PC.try point_sub)
|
||||||
case r of
|
case r of
|
||||||
Nothing -> pure lab
|
Nothing -> pure lab
|
||||||
Just sub -> pure $ lab <> sub
|
Just sub -> pure $ lab <> sub
|
||||||
|
Loading…
Reference in New Issue
Block a user