From: Bob Halley Date: Tue, 16 Aug 2022 23:44:35 +0000 (-0700) Subject: add $ to allow_directives if missing X-Git-Tag: v2.3.0rc1~53^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F833%2Fhead;p=thirdparty%2Fdnspython.git add $ to allow_directives if missing --- diff --git a/dns/zonefile.py b/dns/zonefile.py index 3d3aa61d..a17ebff2 100644 --- a/dns/zonefile.py +++ b/dns/zonefile.py @@ -79,6 +79,13 @@ SavedStateType = Tuple[ ] # default_ttl_known +def _upper_dollarize(s): + s = s.upper() + if not s.startswith("$"): + s = "$" + s + return s + + class Reader: """Read a DNS zone file into a transaction.""" @@ -126,7 +133,7 @@ class Reader: else: # Note that if directives are explicitly specified, then allow_include # is ignored. - self.allowed_directives = set(d.upper() for d in allow_directives) + self.allowed_directives = set(_upper_dollarize(d) for d in allow_directives) self.force_name = force_name self.force_ttl = force_ttl self.force_rdclass = force_rdclass diff --git a/tests/test_zone.py b/tests/test_zone.py index 5dfa6ff0..6b9e2b5e 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -872,6 +872,16 @@ class ZoneTestCase(unittest.TestCase): z2 = dns.zone.from_file(here("example"), "example.", relativize=True) self.assertEqual(z1, z2) + def testExplicitIncludeNotUpperNoDollar(self): + z1 = dns.zone.from_text( + include_text, + "example.", + relativize=True, + allow_directives={"InClUdE", "origin", "TTL"}, + ) + z2 = dns.zone.from_file(here("example"), "example.", relativize=True) + self.assertEqual(z1, z2) + def testExplicitLowerCase(self): z1 = dns.zone.from_text( include_text,