From: Victor Stinner Date: Mon, 26 Jan 2015 15:41:32 +0000 (+0100) Subject: Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and X-Git-Tag: v3.5.0a1~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29dacf2e97314a16db3f2bef492d1c46f39ad656;p=python 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. --- diff --git a/Misc/ACKS b/Misc/ACKS index 6a023146a4..b6ccdc60fc 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index d9acd56710..dd2fe5311f 100644 --- 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. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 03f795cf06..101bfbc85a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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); }