8000 [3.11] gh-63283: IDNA prefix should be case insensitive (GH-17726) by miss-islington · Pull Request #116867 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.11] gh-63283: IDNA prefix should be case insensitive (GH-17726) #116867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-63283: IDNA prefix should be case insensitive (GH-17726)
Any capitalization of "xn--" should be acceptable for the ACE prefix
(see https://tools.ietf.org/html/rfc3490GH-section-5).

(cherry picked from commit d180b50)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Pepijn de Vos <pepijndevos@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
  • Loading branch information
4 people authored and miss-islington committed Mar 15, 2024
commit 14a63c5164e1e9bc960e6e360733c60cb252aa23
6 changes: 3 additions & 3 deletions Lib/encodings/idna.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ToASCII(label):
raise UnicodeError("label empty or too long")

# Step 5: Check ACE prefix
if label.startswith(sace_prefix):
if label[:4].lower() == sace_prefix:
raise UnicodeError("Label starts with ACE prefix")

# Step 6: Encode with PUNYCODE
Expand Down Expand Up @@ -119,7 +119,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[:4].lower() == ace_prefix:
return str(label, "ascii")

# Step 4: Remove ACE prefix
Expand Down Expand Up @@ -192,7 +192,7 @@ def decode(self, input, errors='strict'):
# 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)
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,13 @@ def test_builtin_decode(self):
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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :mod:`encodings.idna`, any capitalization of the the ACE prefix
(``xn--``) is now acceptable. Patch by Pepijn de Vos and Zackery Spytz.
0