diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2020-02-25 03:19:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 03:19:03 (GMT) |
commit | ba22e8f174309979d90047c5dc64fcb63bc2c32e (patch) | |
tree | fe5add86cf54ab65ba7fdc1cc48bc23685884835 /Lib/test | |
parent | 8af4712a16e4b7d1b60f1faec13cd7a88da95f6a (diff) | |
download | cpython-ba22e8f174309979d90047c5dc64fcb63bc2c32e.zip cpython-ba22e8f174309979d90047c5dc64fcb63bc2c32e.tar.gz cpython-ba22e8f174309979d90047c5dc64fcb63bc2c32e.tar.bz2 |
bpo-30566: Fix IndexError when using punycode codec (GH-18632)
Trying to decode an invalid string with the punycode codec
shoud raise UnicodeError.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_codecs.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 3aec34c..8d9cb90 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1343,6 +1343,18 @@ class PunycodeTest(unittest.TestCase): puny = puny.decode("ascii").encode("ascii") self.assertEqual(uni, puny.decode("punycode")) + def test_decode_invalid(self): + testcases = [ + (b"xn--w&", "strict", UnicodeError()), + (b"xn--w&", "ignore", "xn-"), + ] + for puny, errors, expected in testcases: + with self.subTest(puny=puny, errors=errors): + if isinstance(expected, Exception): + self.assertRaises(UnicodeError, puny.decode, "punycode", errors) + else: + self.assertEqual(puny.decode("punycode", errors), expected) + # From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html nameprep_tests = [ |