bpo-19083: IDNA prefix should be case insensitive
Any capitalization of "xn--" should be acceptable for the ACE prefix (see https://tools.ietf.org/html/rfc3490#section-5). Co-Authored-By: Pepijn de Vos <pepijndevos@gmail.com>
This commit is contained in:
parent
98f0f04b50
commit
8ba363238e
|
@ -88,7 +88,7 @@ def ToASCII(label):
|
|||
raise UnicodeError("label empty or too long")
|
||||
|
||||
# Step 5: Check ACE prefix
|
||||
if label.startswith(sace_prefix):
|
||||
if label.lower().startswith(sace_prefix):
|
||||
raise UnicodeError("Label starts with ACE prefix")
|
||||
|
||||
# Step 6: Encode with PUNYCODE
|
||||
|
@ -121,7 +121,7 @@ def ToUnicode(label):
|
|||
except UnicodeError:
|
||||
raise UnicodeError("Invalid character in IDN label")
|
||||
# Step 3: Check for ACE prefix
|
||||
if not label.startswith(ace_prefix):
|
||||
if not label.lower().startswith(ace_prefix):
|
||||
return str(label, "ascii")
|
||||
|
||||
# Step 4: Remove ACE prefix
|
||||
|
@ -194,7 +194,7 @@ class Codec(codecs.Codec):
|
|||
# XXX obviously wrong, see #3232
|
||||
input = bytes(input)
|
||||
|
||||
if ace_prefix not in input:
|
||||
if ace_prefix not in input.lower():
|
||||
# Fast path
|
||||
try:
|
||||
return input.decode('ascii'), len(input)
|
||||
|
|
|
@ -1524,6 +1524,13 @@ class IDNACodecTest(unittest.TestCase):
|
|||
self.assertEqual(str(b"python.org.", "idna"), "python.org.")
|
||||
self.assertEqual(str(b"xn--pythn-mua.org", "idna"), "pyth\xf6n.org")
|
||||
self.assertEqual(str(b"xn--pythn-mua.org.", "idna"), "pyth\xf6n.org.")
|
||||
self.assertEqual(str(b"XN--pythn-mua.org.", "idna"), "pyth\xf6n.org.")
|
||||
self.assertEqual(str(b"xN--pythn-mua.org.", "idna"), "pyth\xf6n.org.")
|
||||
self.assertEqual(str(b"Xn--pythn-mua.org.", "idna"), "pyth\xf6n.org.")
|
||||
self.assertEqual(str(b"bugs.xn--pythn-mua.org.", "idna"),
|
||||
"bugs.pyth\xf6n.org.")
|
||||
self.assertEqual(str(b"bugs.XN--pythn-mua.org.", "idna"),
|
||||
"bugs.pyth\xf6n.org.")
|
||||
|
||||
def test_builtin_encode(self):
|
||||
self.assertEqual("python.org".encode("idna"), b"python.org")
|
||||
|
|
Loading…
Reference in New Issue