cpython: 6ac4f1609847 (original) (raw)

--- 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.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.assertEqual( codecs.charmap_decode(b"\x00\x01\x02", "replace", {0: 'a', 1: 'b'}), @@ -1805,6 +1820,13 @@ class CharmapTest(unittest.TestCase): ("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) )

+ allbytes = bytes(range(256)) self.assertEqual( codecs.charmap_decode(allbytes, "ignore", {}), @@ -1857,6 +1886,11 @@ class CharmapTest(unittest.TestCase): {0: a, 1: b}, )

+ self.assertEqual( codecs.charmap_decode(b"\x00\x01\x02", "replace", {0: a, 1: b}), @@ -1864,11 +1898,23 @@ class CharmapTest(unittest.TestCase): ) self.assertEqual(

+

+ class WithStmtTest(unittest.TestCase): def test_encodedfile(self):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.3.1? Core and Builtins ----------------- +- Issue #14850: Now a chamap decoder treates U+FFFE as "undefined mapping"

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -7511,15 +7511,18 @@ Error: if (PyErr_ExceptionMatches(PyExc_LookupError)) { /* No mapping found means: mapping is undefined. */ PyErr_Clear();

/* Apply mapping */

@@ -7530,21 +7533,6 @@ Error: if (unicode_putchar(&v, &outpos, value) < 0) goto onError; }

@@ -7554,8 +7542,10 @@ Error: if (targetsize == 1) { /* 1-1 mapping */

@@ -7590,6 +7580,19 @@ Error: } Py_DECREF(x); ++s;

+Undefined: