Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29dacf2

Browse files
committed
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.
1 parent a8efc96 commit 29dacf2

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Richard Barran
8989
Cesar Eduardo Barros
9090
Des Barry
9191
Ulf Bartelt
92+
Campbell Barton
9293
Don Bashford
9394
Pior Bastida
9495
Nick Bastin

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15859: PyUnicode_EncodeFSDefault(), PyUnicode_EncodeMBCS() and
14+
PyUnicode_EncodeCodePage() now raise an exception if the object is not an
15+
Unicode object. For PyUnicode_EncodeFSDefault(), it was already the case on
16+
platforms other than Windows. Patch written by Campbell Barton.
17+
1318
- Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
1419
returned NotImplemented. Original patch by Martin Panter.
1520

Objects/unicodeobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7431,6 +7431,11 @@ encode_code_page(int code_page,
74317431
Py_ssize_t offset;
74327432
int chunk_len, ret, done;
74337433

7434+
if (!PyUnicode_Check(unicode)) {
7435+
PyErr_BadArgument();
7436+
return NULL;
7437+
}
7438+
74347439
if (PyUnicode_READY(unicode) == -1)
74357440
return NULL;
74367441
len = PyUnicode_GET_LENGTH(unicode);
@@ -7504,10 +7509,6 @@ PyUnicode_EncodeCodePage(int code_page,
75047509
PyObject *
75057510
PyUnicode_AsMBCSString(PyObject *unicode)
75067511
{
7507-
if (!PyUnicode_Check(unicode)) {
7508-
PyErr_BadArgument();
7509-
return NULL;
7510-
}
75117512
return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL);
75127513
}
75137514

0 commit comments

Comments
 (0)