Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,18 @@ def test_decode_with_int2str_map(self):
("", 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):
a = ord('a')
b = ord('b')
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7998,7 +7998,7 @@ charmap_decode_mapping(const char *s,
goto Undefined;
if (value < 0 || value > MAX_UNICODE) {
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);
goto onError;
}
Expand Down