]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix problems with
authorBob Halley <halley@dnspython.org>
Sun, 8 May 2016 18:53:19 +0000 (11:53 -0700)
committerBob Halley <halley@dnspython.org>
Sun, 8 May 2016 18:53:19 +0000 (11:53 -0700)
dns.name.from_unicode(u'\u00ff' * 60)
dns.name.from_unicode(u'\\255')

dns/name.py

index 1fc56ed772f168ee5fa8c8c7b81c6d39f2ad1744..e8cb3513332b7730a670fd15a7643d1a3f7615ce 100644 (file)
@@ -624,14 +624,14 @@ def from_unicode(text, origin=root):
                     edigits += 1
                     if edigits == 3:
                         escaping = False
-                        label += chr(total)
+                        label += unichr(total)
             elif c in [u'.', u'\u3002', u'\uff0e', u'\uff61']:
                 if len(label) == 0:
                     raise EmptyLabel
-                if len(label) > 63:
-                    # otherwise encodings.idna raises UnicodeError later
+                try:
+                    labels.append(encodings.idna.ToASCII(label))
+                except UnicodeError:
                     raise LabelTooLong
-                labels.append(encodings.idna.ToASCII(label))
                 label = u''
             elif c == u'\\':
                 escaping = True
@@ -641,11 +641,11 @@ def from_unicode(text, origin=root):
                 label += c
         if escaping:
             raise BadEscape
-        if len(label) > 63:
-            # otherwise encodings.idna raises UnicodeError later
-            raise LabelTooLong
         if len(label) > 0:
-            labels.append(encodings.idna.ToASCII(label))
+            try:
+                labels.append(encodings.idna.ToASCII(label))
+            except UnicodeError:
+                raise LabelTooLong
         else:
             labels.append(b'')