]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Handle DHCP servers returning domains prefixed by dot [#687].
authorBob Halley <halley@dnspython.org>
Sun, 7 Nov 2021 18:41:54 +0000 (10:41 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 7 Nov 2021 18:41:54 +0000 (10:41 -0800)
dns/resolver.py
tests/test_resolver.py

index 108dd52db8b926ec804cd26b57e381b86669160c..fbdf62257b97241057aca4aa8b7569839b5e9d0d 100644 (file)
@@ -875,6 +875,11 @@ class BaseResolver:
                 self.nameservers.append(ns)
 
     def _config_win32_domain(self, domain):  # pragma: no cover
+        # Sometimes DHCP servers add a '.' prefix to the default domain, and
+        # Windows just stores such values in the registry (see #687).
+        # Check for this and fix it.
+        if domain.startswith('.'):
+            domain = domain[1:]
         # we call str() on domain to convert it from unicode to ascii
         self.domain = dns.name.from_text(str(domain))
 
index ecd1bf22f7895e616898bb2b3278703c23c61a0c..eb8389328a92b5b07f4d3acd9f7e6f738fa03c5d 100644 (file)
@@ -886,6 +886,16 @@ class ResolverMiscTestCase(unittest.TestCase):
         # not raising is the test
         res._compute_timeout(now + 0.5)
 
+    def test_configure_win32_domain(self):
+        # This is a win32-related test but it works on all platforms so we
+        # test it that way to make coverage analysis easier.
+        n = dns.name.from_text('home.')
+        res = dns.resolver.Resolver(configure=False)
+        res._config_win32_domain('home')
+        self.assertEqual(res.domain, n)
+        res._config_win32_domain('.home')
+        self.assertEqual(res.domain, n)
+
 
 class ResolverNameserverValidTypeTestCase(unittest.TestCase):
     def test_set_nameservers_to_list(self):