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.
This commit is contained in:
Victor Stinner 2015-01-26 16:41:32 +01:00
parent a8efc9601d
commit 29dacf2e97
3 changed files with 11 additions and 4 deletions

View file

@ -89,6 +89,7 @@ Richard Barran
Cesar Eduardo Barros Cesar Eduardo Barros
Des Barry Des Barry
Ulf Bartelt Ulf Bartelt
Campbell Barton
Don Bashford Don Bashford
Pior Bastida Pior Bastida
Nick Bastin Nick Bastin

View file

@ -10,6 +10,11 @@ Release date: TBA
Core and Builtins 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__() - Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
returned NotImplemented. Original patch by Martin Panter. returned NotImplemented. Original patch by Martin Panter.

View file

@ -7431,6 +7431,11 @@ encode_code_page(int code_page,
Py_ssize_t offset; Py_ssize_t offset;
int chunk_len, ret, done; int chunk_len, ret, done;
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(unicode) == -1) if (PyUnicode_READY(unicode) == -1)
return NULL; return NULL;
len = PyUnicode_GET_LENGTH(unicode); len = PyUnicode_GET_LENGTH(unicode);
@ -7504,10 +7509,6 @@ PyUnicode_EncodeCodePage(int code_page,
PyObject * PyObject *
PyUnicode_AsMBCSString(PyObject *unicode) PyUnicode_AsMBCSString(PyObject *unicode)
{ {
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL); return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL);
} }