diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-19 17:38:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-19 17:38:19 (GMT) |
commit | 35804e4c63ae0a61adb71ced8ea6ddcf68908d41 (patch) | |
tree | ac9c542920e18a251f7df0175e6d4602771463f1 /Lib | |
parent | 507c591e5bb9b850c9d996d8148cb669f1b5d62b (diff) | |
download | cpython-35804e4c63ae0a61adb71ced8ea6ddcf68908d41.zip cpython-35804e4c63ae0a61adb71ced8ea6ddcf68908d41.tar.gz cpython-35804e4c63ae0a61adb71ced8ea6ddcf68908d41.tar.bz2 |
Issue #19279: UTF-7 decoder no more produces illegal strings.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_codecs.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index c68088e..80ec541 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -820,6 +820,36 @@ class UTF7Test(ReadTest, unittest.TestCase): ] ) + def test_errors(self): + tests = [ + (b'a\xffb', 'a\ufffdb'), + (b'a+IK', 'a\ufffd'), + (b'a+IK-b', 'a\ufffdb'), + (b'a+IK,b', 'a\ufffdb'), + (b'a+IKx', 'a\u20ac\ufffd'), + (b'a+IKx-b', 'a\u20ac\ufffdb'), + (b'a+IKwgr', 'a\u20ac\ufffd'), + (b'a+IKwgr-b', 'a\u20ac\ufffdb'), + (b'a+IKwgr,', 'a\u20ac\ufffd'), + (b'a+IKwgr,-b', 'a\u20ac\ufffd-b'), + (b'a+IKwgrB', 'a\u20ac\u20ac\ufffd'), + (b'a+IKwgrB-b', 'a\u20ac\u20ac\ufffdb'), + (b'a+/,+IKw-b', 'a\ufffd\u20acb'), + (b'a+//,+IKw-b', 'a\ufffd\u20acb'), + (b'a+///,+IKw-b', 'a\uffff\ufffd\u20acb'), + (b'a+////,+IKw-b', 'a\uffff\ufffd\u20acb'), + ] + for raw, expected in tests: + with self.subTest(raw=raw): + self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode, + raw, 'strict', True) + self.assertEqual(raw.decode('utf-7', 'replace'), expected) + + def test_nonbmp(self): + self.assertEqual('\U000104A0'.encode(self.encoding), b'+2AHcoA-') + self.assertEqual('\ud801\udca0'.encode(self.encoding), b'+2AHcoA-') + self.assertEqual(b'+2AHcoA-'.decode(self.encoding), '\U000104A0') + class UTF16ExTest(unittest.TestCase): def test_errors(self): |