summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-07-20 22:52:06 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-07-20 22:52:06 (GMT)
commit715a63b78349952ccc0fb3dd3139e2d822006d35 (patch)
treed1474f149df204365adc6c07ba57469753124145 /Lib/test/test_codecs.py
parentbee739baa771b7c54169e799fbfe1a55c5fce3d6 (diff)
downloadcpython-715a63b78349952ccc0fb3dd3139e2d822006d35.zip
cpython-715a63b78349952ccc0fb3dd3139e2d822006d35.tar.gz
cpython-715a63b78349952ccc0fb3dd3139e2d822006d35.tar.bz2
Issue #14579: Fix error handling bug in the utf-16 decoder.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index d434f83..57669f8 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -495,7 +495,19 @@ class UTF16LETest(ReadTest):
)
def test_errors(self):
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode, "\xff", "strict", True)
+ tests = [
+ (b'\xff', u'\ufffd'),
+ (b'A\x00Z', u'A\ufffd'),
+ (b'A\x00B\x00C\x00D\x00Z', u'ABCD\ufffd'),
+ (b'\x00\xd8', u'\ufffd'),
+ (b'\x00\xd8A', u'\ufffd'),
+ (b'\x00\xd8A\x00', u'\ufffdA'),
+ (b'\x00\xdcA\x00', u'\ufffdA'),
+ ]
+ for raw, expected in tests:
+ self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
+ raw, 'strict', True)
+ self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
class UTF16BETest(ReadTest):
encoding = "utf-16-be"
@@ -516,7 +528,19 @@ class UTF16BETest(ReadTest):
)
def test_errors(self):
- self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode, "\xff", "strict", True)
+ tests = [
+ (b'\xff', u'\ufffd'),
+ (b'\x00A\xff', u'A\ufffd'),
+ (b'\x00A\x00B\x00C\x00DZ', u'ABCD\ufffd'),
+ (b'\xd8\x00', u'\ufffd'),
+ (b'\xd8\x00\xdc', u'\ufffd'),
+ (b'\xd8\x00\x00A', u'\ufffdA'),
+ (b'\xdc\x00\x00A', u'\ufffdA'),
+ ]
+ for raw, expected in tests:
+ self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
+ raw, 'strict', True)
+ self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
class UTF8Test(ReadTest):
encoding = "utf-8"