]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix exception when reading from a masterfile.
authorBob Halley <halley@dnspython.org>
Sat, 21 Jun 2014 14:45:14 +0000 (07:45 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 21 Jun 2014 14:45:14 +0000 (07:45 -0700)
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
dns/zone.py
tests/test_zone.py

index 903b5890bc04c8061458fa569611e13aa2c32a94..b9d204a860085f2df72d349cf4511dc4111dfe71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-21  Bob Halley  <halley@dnspython.org>
+
+    * 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  <halley@dnspython.org>
 
     * Escaping of Unicode has been corrected.  Previously we escaped and
index ab57148077f734c7907a9f72a3e689ed2f55deca..6f3448347356e15bbf6ff6014515b0fc7ae4e8cb 100644 (file)
@@ -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
index 31e7405b0f8d994e6ea2a0f73da22043f9156d8c..551530a6b8e8cfd0f95ba574e438746df63b315e 100644 (file)
@@ -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()