mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fix wrong bytes type conversion in PyUnicode_AsUnicodeEscapeString.
Fix wrong bytes type conversion in PyUnicode_AsUnicodeDecodeString.
This commit is contained in:
parent
554d878b1c
commit
9cb6f7f7a5
1 changed files with 4 additions and 15 deletions
|
@ -3257,20 +3257,14 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
|
||||||
|
|
||||||
PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
|
PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
|
||||||
{
|
{
|
||||||
PyObject *s, *result;
|
PyObject *s;
|
||||||
if (!PyUnicode_Check(unicode)) {
|
if (!PyUnicode_Check(unicode)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(unicode),
|
s = PyUnicode_EncodeUnicodeEscape(PyUnicode_AS_UNICODE(unicode),
|
||||||
PyUnicode_GET_SIZE(unicode));
|
PyUnicode_GET_SIZE(unicode));
|
||||||
|
return s;
|
||||||
if (!s)
|
|
||||||
return NULL;
|
|
||||||
result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s),
|
|
||||||
PyByteArray_GET_SIZE(s));
|
|
||||||
Py_DECREF(s);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Raw Unicode Escape Codec ------------------------------------------- */
|
/* --- Raw Unicode Escape Codec ------------------------------------------- */
|
||||||
|
@ -3482,7 +3476,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
|
||||||
|
|
||||||
PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
|
PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
|
||||||
{
|
{
|
||||||
PyObject *s, *result;
|
PyObject *s;
|
||||||
if (!PyUnicode_Check(unicode)) {
|
if (!PyUnicode_Check(unicode)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3490,12 +3484,7 @@ PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
|
||||||
s = PyUnicode_EncodeRawUnicodeEscape(PyUnicode_AS_UNICODE(unicode),
|
s = PyUnicode_EncodeRawUnicodeEscape(PyUnicode_AS_UNICODE(unicode),
|
||||||
PyUnicode_GET_SIZE(unicode));
|
PyUnicode_GET_SIZE(unicode));
|
||||||
|
|
||||||
if (!s)
|
return s;
|
||||||
return NULL;
|
|
||||||
result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(s),
|
|
||||||
PyByteArray_GET_SIZE(s));
|
|
||||||
Py_DECREF(s);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Unicode Internal Codec ------------------------------------------- */
|
/* --- Unicode Internal Codec ------------------------------------------- */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue