summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-15 13:30:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-15 13:30:04 (GMT)
commit55e2cb497bc35c6bf31673dce4d1ec4de0cb87d0 (patch)
tree8d4b1dcdcead0963ef270fdf80393dec0c045dda /Lib
parentb946af58978ebe29ff6149e8f31e0edc299e4c03 (diff)
parent45d16d99240506df8d943c81017880977612488b (diff)
downloadcpython-55e2cb497bc35c6bf31673dce4d1ec4de0cb87d0.zip
cpython-55e2cb497bc35c6bf31673dce4d1ec4de0cb87d0.tar.gz
cpython-55e2cb497bc35c6bf31673dce4d1ec4de0cb87d0.tar.bz2
Issue #14850: Now a chamap decoder treates U+FFFE as "undefined mapping"
in any mapping, not only in an unicode string.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_codecs.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 7eb5529..5be78d7 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1737,6 +1737,10 @@ class CharmapTest(unittest.TestCase):
codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab"
)
+ self.assertRaises(UnicodeDecodeError,
+ codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab\ufffe"
+ )
+
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab"),
("ab\ufffd", 3)
@@ -1793,6 +1797,17 @@ class CharmapTest(unittest.TestCase):
{0: 'a', 1: 'b'}
)
+ self.assertRaises(UnicodeDecodeError,
+ codecs.charmap_decode, b"\x00\x01\x02", "strict",
+ {0: 'a', 1: 'b', 2: None}
+ )
+
+ # Issue #14850
+ self.assertRaises(UnicodeDecodeError,
+ codecs.charmap_decode, b"\x00\x01\x02", "strict",
+ {0: 'a', 1: 'b', 2: '\ufffe'}
+ )
+
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: 'a', 1: 'b'}),
@@ -1805,6 +1820,13 @@ class CharmapTest(unittest.TestCase):
("ab\ufffd", 3)
)
+ # Issue #14850
+ self.assertEqual(
+ codecs.charmap_decode(b"\x00\x01\x02", "replace",
+ {0: 'a', 1: 'b', 2: '\ufffe'}),
+ ("ab\ufffd", 3)
+ )
+
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: 'a', 1: 'b'}),
@@ -1817,6 +1839,13 @@ class CharmapTest(unittest.TestCase):
("ab", 3)
)
+ # Issue #14850
+ self.assertEqual(
+ codecs.charmap_decode(b"\x00\x01\x02", "ignore",
+ {0: 'a', 1: 'b', 2: '\ufffe'}),
+ ("ab", 3)
+ )
+
allbytes = bytes(range(256))
self.assertEqual(
codecs.charmap_decode(allbytes, "ignore", {}),
@@ -1857,6 +1886,11 @@ class CharmapTest(unittest.TestCase):
{0: a, 1: b},
)
+ self.assertRaises(UnicodeDecodeError,
+ codecs.charmap_decode, b"\x00\x01\x02", "strict",
+ {0: a, 1: b, 2: 0xFFFE},
+ )
+
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: a, 1: b}),
@@ -1864,11 +1898,23 @@ class CharmapTest(unittest.TestCase):
)
self.assertEqual(
+ codecs.charmap_decode(b"\x00\x01\x02", "replace",
+ {0: a, 1: b, 2: 0xFFFE}),
+ ("ab\ufffd", 3)
+ )
+
+ self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: a, 1: b}),
("ab", 3)
)
+ self.assertEqual(
+ codecs.charmap_decode(b"\x00\x01\x02", "ignore",
+ {0: a, 1: b, 2: 0xFFFE}),
+ ("ab", 3)
+ )
+
class WithStmtTest(unittest.TestCase):
def test_encodedfile(self):