Skip to content
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
2 changes: 1 addition & 1 deletion Lib/encodings/punycode.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def decode_generalized_number(extended, extpos, bias, errors):
digit = char - 22 # 0x30-26
elif errors == "strict":
raise UnicodeError("Invalid extended code point '%s'"
% extended[extpos])
% extended[extpos-1])
else:
return extpos, None
t = T(j, bias)
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,11 @@ def test_recoding(self):
if len(i)!=2:
print(repr(i))

punycode_decode_exceptions = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename this to invalid_punycode_testcases.

(b"xn--w&",
UnicodeError),
]


class PunycodeTest(unittest.TestCase):
def test_encode(self):
Expand All @@ -1355,6 +1360,12 @@ def test_decode(self):
puny = puny.decode("ascii").encode("ascii")
self.assertEqual(uni, puny.decode("punycode"))

# Make sure punycode codec raises the right kind of exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: We can drop this comment.

# when given invalid punycode to decode
def test_decode_exceptions(self):
for byt, exception in punycode_decode_exceptions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename byt to puny.

with self.assertRaises(exception):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We couls use self.subTest() to make test failure messages clearer.

byt.decode('punycode')

class UnicodeInternalTest(unittest.TestCase):
@unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t')
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ Rycharde Hawkes
Ben Hayden
Jochen Hayek
Tim Heaney
Vikram Hegde
Henrik Heimbuerger
Christian Heimes
Thomas Heller
Expand Down