summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-25 03:42:39 (GMT)
committerGitHub <noreply@github.com>2020-02-25 03:42:39 (GMT)
commitdaef21ce7dfd3735101d85d6ebf7554187c33ab8 (patch)
tree5d82af9309af1da8df7a385e2e2b1692e5f0cf0f /Lib/test
parent1f4cf0c22b00fefb17611546755b65d3cb488330 (diff)
downloadcpython-daef21ce7dfd3735101d85d6ebf7554187c33ab8.zip
cpython-daef21ce7dfd3735101d85d6ebf7554187c33ab8.tar.gz
cpython-daef21ce7dfd3735101d85d6ebf7554187c33ab8.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. (cherry picked from commit ba22e8f174309979d90047c5dc64fcb63bc2c32e) Co-authored-by: Berker Peksag <berker.peksag@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_codecs.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index b37525b..8c10e94 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1331,6 +1331,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 = [