Skip to content

Commit 3635388

Browse files
authored
bpo-42065: Fix incorrectly formatted _codecs.charmap_decode error message (GH-19940)
1 parent 975d10a commit 3635388

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Lib/test/test_codecs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,18 @@ def test_decode_with_int2str_map(self):
21972197
("", len(allbytes))
21982198
)
21992199

2200+
self.assertRaisesRegex(TypeError,
2201+
"character mapping must be in range\\(0x110000\\)",
2202+
codecs.charmap_decode,
2203+
b"\x00\x01\x02", "strict", {0: "A", 1: 'Bb', 2: -2}
2204+
)
2205+
2206+
self.assertRaisesRegex(TypeError,
2207+
"character mapping must be in range\\(0x110000\\)",
2208+
codecs.charmap_decode,
2209+
b"\x00\x01\x02", "strict", {0: "A", 1: 'Bb', 2: 999999999}
2210+
)
2211+
22002212
def test_decode_with_int2int_map(self):
22012213
a = ord('a')
22022214
b = ord('b')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix an incorrectly formatted error from :meth:`_codecs.charmap_decode` when
2+
called with a mapped value outside the range of valid Unicode code points.
3+
PR by Max Bernstein.

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8304,7 +8304,7 @@ charmap_decode_mapping(const char *s,
83048304
goto Undefined;
83058305
if (value < 0 || value > MAX_UNICODE) {
83068306
PyErr_Format(PyExc_TypeError,
8307-
"character mapping must be in range(0x%lx)",
8307+
"character mapping must be in range(0x%x)",
83088308
(unsigned long)MAX_UNICODE + 1);
83098309
goto onError;
83108310
}

0 commit comments

Comments
 (0)