]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42065: Fix incorrectly formatted _codecs.charmap_decode error message (GH-19940)
authorMax Bernstein <tekknolagi@users.noreply.github.com>
Sat, 17 Oct 2020 20:38:21 +0000 (13:38 -0700)
committerGitHub <noreply@github.com>
Sat, 17 Oct 2020 20:38:21 +0000 (23:38 +0300)
Lib/test/test_codecs.py
Misc/NEWS.d/next/Library/2020-10-17-23-17-18.bpo-42065.85BsRA.rst [new file with mode: 0644]
Objects/unicodeobject.c

index 9be8281ce5af5cac95dd5a82fc2e9e01ec3989d9..328a47b2e376693d80d24d813abf9f282d3ab3b5 100644 (file)
@@ -2197,6 +2197,18 @@ class CharmapTest(unittest.TestCase):
             ("", 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')
diff --git a/Misc/NEWS.d/next/Library/2020-10-17-23-17-18.bpo-42065.85BsRA.rst b/Misc/NEWS.d/next/Library/2020-10-17-23-17-18.bpo-42065.85BsRA.rst
new file mode 100644 (file)
index 0000000..83c86c0
--- /dev/null
@@ -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.
index 01e5c728b383fb45b72dc8752ea5bc1b3c4b8424..c4e73ebd45d2065cdeda9e2d8b186721a43a3abf 100644 (file)
@@ -8304,7 +8304,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;
             }