]> granicus.if.org Git - python/commitdiff
Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 26 Jan 2015 15:41:32 +0000 (16:41 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 26 Jan 2015 15:41:32 +0000 (16:41 +0100)
PyUnicode_EncodeCodePage() now raise an exception if the object is not an
Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on
platforms other than Windows. Patch written by Campbell Barton.

Misc/ACKS
Misc/NEWS
Objects/unicodeobject.c

index 6a023146a423eb03bd0f9fc751f86b2c44782408..b6ccdc60fc224fb7e313e48bf5f6406ef6109d76 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -89,6 +89,7 @@ Richard Barran
 Cesar Eduardo Barros
 Des Barry
 Ulf Bartelt
+Campbell Barton
 Don Bashford
 Pior Bastida
 Nick Bastin
index d9acd567101d69ee00fce111c41d16cbeb2d3ee0..dd2fe5311f66c0bb335bbfa485f4b87eac1a0291 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and
+  PyUnicode_EncodeCodePage() now raise an exception if the object is not an
+  Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on
+  platforms other than Windows. Patch written by Campbell Barton.
+
 - Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
   returned NotImplemented.  Original patch by Martin Panter.
 
index 03f795cf06a12a32ef3063ecbc11e8619d6b72cd..101bfbc85a087b4a69bbed2a0158be029907d81a 100644 (file)
@@ -7431,6 +7431,11 @@ encode_code_page(int code_page,
     Py_ssize_t offset;
     int chunk_len, ret, done;
 
+    if (!PyUnicode_Check(unicode)) {
+        PyErr_BadArgument();
+        return NULL;
+    }
+
     if (PyUnicode_READY(unicode) == -1)
         return NULL;
     len = PyUnicode_GET_LENGTH(unicode);
@@ -7504,10 +7509,6 @@ PyUnicode_EncodeCodePage(int code_page,
 PyObject *
 PyUnicode_AsMBCSString(PyObject *unicode)
 {
-    if (!PyUnicode_Check(unicode)) {
-        PyErr_BadArgument();
-        return NULL;
-    }
     return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL);
 }