Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11)

Unified Diff: Lib/encodings/idna.py

Issue 9682: socket.create_connection error message for domain subpart with invalid length is very confusing
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/encodings/idna.py Sun Apr 14 19:22:47 2013 +0200
+++ b/Lib/encodings/idna.py Sun May 05 15:22:56 2013 -0400
@@ -59,7 +59,15 @@
return label
+def _raise_max_length_error(label):
+ raise UnicodeError("label %r is too long" % label.decode())
+
+def _raise_min_length_error(label, labels=None):
+ value = ' in %r' % labels.decode() if labels else ''
+ raise UnicodeError("empty label%r" % value)
+
def ToASCII(label):
+
try:
# Step 1: try ASCII
label = label.encode("ascii")
@@ -68,9 +76,11 @@
else:
# Skip to step 3: UseSTD3ASCIIRules is false, so
# Skip to step 8.
- if 0 < len(label) < 64:
- return label
- raise UnicodeError("label empty or too long")
+ if not label:
+ _raise_min_length_error(label)
+ if len(label) >=64 :
+ _raise_max_length_error(label)
+ return label
# Step 2: nameprep
label = nameprep(label)
@@ -83,9 +93,11 @@
pass
else:
# Skip to step 8.
- if 0 < len(label) < 64:
- return label
- raise UnicodeError("label empty or too long")
+ if not label:
+ _raise_min_length_error(label)
+ if len(label) >= 64:
+ _raise_max_length_error(label)
+ return label
# Step 5: Check ACE prefix
if label.startswith(sace_prefix):
@@ -98,9 +110,9 @@
label = ace_prefix + label
# Step 8: Check size
- if 0 < len(label) < 64:
- return label
- raise UnicodeError("label empty or too long")
+ if len(label) >= 64:
+ _raise_max_length_error(label)
+ return label
def ToUnicode(label):
# Step 1: Check for ASCII
@@ -161,10 +173,13 @@
# ASCII name: fast path
labels = result.split(b'.')
for label in labels[:-1]:
- if not (0 < len(label) < 64):
- raise UnicodeError("label empty or too long")
+ if not label:
+ _raise_min_length_error(label, result)
+ if len(label) >= 64:
+ _raise_max_length_error(label)
if len(labels[-1]) >= 64:
- raise UnicodeError("label too long")
+ _raise_max_length_error(labels[-1])
+
return result, len(input)
result = bytearray()
« no previous file with comments | « no previous file | Lib/test/test_unicode.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+