]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
When dealing with an IDNA 2003 non-punycode label, escapify it before unicode
authorBob Halley <halley@dnspython.org>
Mon, 7 Jan 2019 15:35:39 +0000 (07:35 -0800)
committerBob Halley <halley@dnspython.org>
Mon, 7 Jan 2019 15:35:39 +0000 (07:35 -0800)
conversion.  This ensures that labels with codepoints that need escaping
get it, as opposed to raising an exception because we tried to interpret a
non-UTF-8 sequence as UTF-8.

dns/name.py
tests/test_name.py

index a9fc177b1ec4342a9cb63c4c36aa07a5ac8ae1e0..c580f5f8b34e95be7102b60c3ced67dbd64c808a 100644 (file)
@@ -121,8 +121,6 @@ class IDNACodec(object):
                 label = label[4:].decode('punycode')
             except Exception as e:
                 raise IDNAException(idna_exception=e)
-        else:
-            label = label.decode()
         return _escapify(label)
 
 
index bea30a2df7d2c70e490ac98b1d80c9fc479d4daf..54b0f31f5150c8062970fa2a0f47985c93d675a1 100644 (file)
@@ -266,11 +266,11 @@ class NameTestCase(unittest.TestCase):
         self.assertEqual(t, r'\150\151\152\153\154\155\156\157\158\159.')
 
     def testToText14(self):
-        # You can't send this to_unicode() as it wasn't unicode to begin with.
-        def bad():
-            n = dns.name.from_text(r'\150\151\152\153\154\155\156\157\158\159.')
-            t = n.to_unicode()
-        self.failUnlessRaises(UnicodeDecodeError, bad)
+        # Something that didn't start as unicode should go to escapes and not
+        # raise due to interpreting arbitrary binary DNS labels as UTF-8.
+        n = dns.name.from_text(r'\150\151\152\153\154\155\156\157\158\159.')
+        t = n.to_unicode()
+        self.assertEqual(t, r'\150\151\152\153\154\155\156\157\158\159.')
 
     def testSlice1(self):
         n = dns.name.from_text(r'a.b.c.', origin=None)