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