bpo-42065: Fix incorrectly formatted _codecs.charmap_decode error message (GH-19940)

This commit is contained in:
Max Bernstein 2020-10-17 13:38:21 -07:00 committed by GitHub
parent 975d10a4f8
commit 3635388f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -2197,6 +2197,18 @@ class CharmapTest(unittest.TestCase):
("", len(allbytes)) ("", len(allbytes))
) )
self.assertRaisesRegex(TypeError,
"character mapping must be in range\\(0x110000\\)",
codecs.charmap_decode,
b"\x00\x01\x02", "strict", {0: "A", 1: 'Bb', 2: -2}
)
self.assertRaisesRegex(TypeError,
"character mapping must be in range\\(0x110000\\)",
codecs.charmap_decode,
b"\x00\x01\x02", "strict", {0: "A", 1: 'Bb', 2: 999999999}
)
def test_decode_with_int2int_map(self): def test_decode_with_int2int_map(self):
a = ord('a') a = ord('a')
b = ord('b') b = ord('b')

View File

@ -0,0 +1,3 @@
Fix an incorrectly formatted error from :meth:`_codecs.charmap_decode` when
called with a mapped value outside the range of valid Unicode code points.
PR by Max Bernstein.

View File

@ -8304,7 +8304,7 @@ charmap_decode_mapping(const char *s,
goto Undefined; goto Undefined;
if (value < 0 || value > MAX_UNICODE) { if (value < 0 || value > MAX_UNICODE) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"character mapping must be in range(0x%lx)", "character mapping must be in range(0x%x)",
(unsigned long)MAX_UNICODE + 1); (unsigned long)MAX_UNICODE + 1);
goto onError; goto onError;
} }