summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-06-19 11:13:49 -0700
committerBob Halley <halley@dnspython.org>2020-06-19 11:13:49 -0700
commit9f977ee5a71e76d20e74751f34798ab3adb5df90 (patch)
tree98e35e95383dcf249b3afb6a123265ceb3238d8c
parent0a7a6210d8a55f2151818652b4245c81101f402b (diff)
downloaddnspython-9f977ee5a71e76d20e74751f34798ab3adb5df90.tar.gz
we did not check label-too-long in a few text cases
-rw-r--r--dns/name.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/dns/name.py b/dns/name.py
index 677f324..310b032 100644
--- a/dns/name.py
+++ b/dns/name.py
@@ -26,7 +26,7 @@ try:
import idna # type: ignore
have_idna_2008 = True
except ImportError:
- have_idna_2008 = False
+ have_idna_2008 = False # pragma: no cover
import dns.exception
import dns.wiredata
@@ -105,7 +105,7 @@ class IDNACodec:
return label.lower().startswith(b'xn--')
def encode(self, label):
- raise NotImplementedError
+ raise NotImplementedError # pragma: no cover
def decode(self, label):
# We do not apply any IDNA policy on decode.
@@ -191,7 +191,10 @@ class IDNA2008Codec(IDNACodec):
if label == '':
return b''
if self.allow_pure_ascii and is_all_ascii(label):
- return label.encode('ascii')
+ encoded = label.encode('ascii')
+ if len(encoded) > 63:
+ raise LabelTooLong
+ return encoded
if not have_idna_2008:
raise NoIDNA2008
try:
@@ -199,7 +202,10 @@ class IDNA2008Codec(IDNACodec):
label = idna.uts46_remap(label, False, self.transitional)
return idna.alabel(label)
except idna.IDNAError as e:
- raise IDNAException(idna_exception=e)
+ if e.args[0] == 'Label too long':
+ raise LabelTooLong
+ else:
+ raise IDNAException(idna_exception=e)
def decode(self, label):
if not self.strict_decode: