From 56ab1a15c8d4b6a26e0643e5ce3aac7e09f2c9b5 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sat, 21 Jun 2014 07:45:14 -0700 Subject: [PATCH] Fix exception when reading from a masterfile. When reading from a masterfile, if the first content line started with leading whitespace, we raised an ugly exception instead of doing the right thing, namely using the zone origin as the name. [#73] --- ChangeLog | 7 +++++++ dns/zone.py | 2 +- tests/test_zone.py | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 903b5890..b9d204a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-06-21 Bob Halley + + * When reading from a masterfile, if the first content line started + with leading whitespace, we raised an ugly exception instead of + doing the right thing, namely using the zone origin as the name. + [#73] + 2014-06-19 Bob Halley * Escaping of Unicode has been corrected. Previously we escaped and diff --git a/dns/zone.py b/dns/zone.py index ab571480..6f344834 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -558,7 +558,7 @@ class _MasterReader(object): self.current_origin = origin self.relativize = relativize self.ttl = 0 - self.last_name = None + self.last_name = self.current_origin self.zone = zone_factory(origin, rdclass, relativize=relativize) self.saved_state = [] self.current_file = None diff --git a/tests/test_zone.py b/tests/test_zone.py index 31e7405b..551530a6 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -129,7 +129,7 @@ class ZoneTestCase(unittest.TestCase): for n in names: print >> f, z[n].to_text(n) self.failUnless(f.getvalue() == example_text_output) - + def testTorture1(self): # # Read a zone containing all our supported RR types, and @@ -385,5 +385,14 @@ class ZoneTestCase(unittest.TestCase): relativize=True) self.failUnlessRaises(dns.exception.SyntaxError, bad) + def testFirstRRStartsWithWhitespace(self): + # no name is specified, so default to the intial origin + # no ttl is specified, so default to the initial TTL of 0 + z = dns.zone.from_text(' IN A 10.0.0.1', origin='example.', + check_origin=False) + n = z['@'] + rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) + self.failUnless(rds.ttl == 0) + if __name__ == '__main__': unittest.main() -- 2.47.3