From 6550b3f3547735dffb3e8d437c5d622e97cfdf75 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 27 Apr 2025 17:41:11 +0200 Subject: [PATCH] Enable domain wildcards. --- src/GenericParser/DomainParser.purs | 13 ++++++++++++- src/GenericParser/DomainParserRFC1035.purs | 13 ++++++++++++- test/TestValues.purs | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/GenericParser/DomainParser.purs b/src/GenericParser/DomainParser.purs index 9333bae..3b17f47 100644 --- a/src/GenericParser/DomainParser.purs +++ b/src/GenericParser/DomainParser.purs @@ -73,10 +73,21 @@ sub_eof = do -- | From RFC 1035: ::= | " " -- | +-- | Since RFC 1034 requires to accept '*' as leftmost domain label, the rule should be: +-- | ::= | "*." | " " +-- | -- | Accepting an optional '.' at the end of the subdomain doesn't conform -- | to the (prefered) syntax of a domain as described in RFC 1035. -- | However, this last '.' character should be acceptable in most applications. -- | In some cases, a fully qualified domain name (FQDN) such as `example.com.` -- | has to be differenciated from a "relative" name (www). +-- | +-- | For documentation about wildcards, see RFC 4592. domain :: Parser DomainError String -domain = (string " " *> eof) <|> sub_eof +domain = (string " " *> eof) <|> wildcard <|> sub_eof + where + wildcard :: Parser DomainError String + wildcard = do + _ <- string "*." + rest <- sub_eof + pure $ "*." <> rest diff --git a/src/GenericParser/DomainParserRFC1035.purs b/src/GenericParser/DomainParserRFC1035.purs index f3f29a0..5556902 100644 --- a/src/GenericParser/DomainParserRFC1035.purs +++ b/src/GenericParser/DomainParserRFC1035.purs @@ -79,10 +79,21 @@ sub_eof = do -- | From RFC 1035: ::= | " " -- | +-- | Since RFC 1034 requires to accept '*' as leftmost domain label, the rule should be: +-- | ::= | "*." | " " +-- | -- | Accepting an optional '.' at the end of the subdomain doesn't conform -- | to the (prefered) syntax of a domain as described in RFC 1035. -- | However, this last '.' character should be acceptable in most applications. -- | In some cases, a fully qualified domain name (FQDN) such as `example.com.` -- | has to be differenciated from a "relative" name (www). +-- | +-- | For documentation about wildcards, see RFC 4592. domain :: Parser DomainError String -domain = (string " " *> eof) <|> sub_eof +domain = (string " " *> eof) <|> wildcard <|> sub_eof + where + wildcard :: Parser DomainError String + wildcard = do + _ <- string "*." + rest <- sub_eof + pure $ "*." <> rest diff --git a/test/TestValues.purs b/test/TestValues.purs index 029d397..87a26da 100644 --- a/test/TestValues.purs +++ b/test/TestValues.purs @@ -15,6 +15,7 @@ domains , "xblah.a2.org" , "xblah.a33.org" , "_dmarc.example.com" + , "*.example.com" ] ipv4_addresses :: Array String