From 537d2dd0378c1e819b8a65a341ed7dab75c5e444 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sun, 8 May 2016 11:53:19 -0700 Subject: [PATCH] Fix problems with dns.name.from_unicode(u'\u00ff' * 60) dns.name.from_unicode(u'\\255') --- dns/name.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dns/name.py b/dns/name.py index 1fc56ed7..e8cb3513 100644 --- a/dns/name.py +++ b/dns/name.py @@ -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'') -- 2.47.3