mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613)
Previously *consumed was not set in this case.
This commit is contained in:
parent
d460c8ec52
commit
f08e52ccb0
4 changed files with 95 additions and 0 deletions
|
@ -239,6 +239,40 @@ unicode_asutf8andsize(PyObject *self, PyObject *args)
|
|||
return Py_BuildValue("(Nn)", result, utf8_len);
|
||||
}
|
||||
|
||||
/* Test PyUnicode_DecodeUTF8() */
|
||||
static PyObject *
|
||||
unicode_decodeutf8(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *data;
|
||||
Py_ssize_t size;
|
||||
const char *errors = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors))
|
||||
return NULL;
|
||||
|
||||
return PyUnicode_DecodeUTF8(data, size, errors);
|
||||
}
|
||||
|
||||
/* Test PyUnicode_DecodeUTF8Stateful() */
|
||||
static PyObject *
|
||||
unicode_decodeutf8stateful(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *data;
|
||||
Py_ssize_t size;
|
||||
const char *errors = NULL;
|
||||
Py_ssize_t consumed = 123456789;
|
||||
PyObject *result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors))
|
||||
return NULL;
|
||||
|
||||
result = PyUnicode_DecodeUTF8Stateful(data, size, errors, &consumed);
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("(Nn)", result, consumed);
|
||||
}
|
||||
|
||||
/* Test PyUnicode_Concat() */
|
||||
static PyObject *
|
||||
unicode_concat(PyObject *self, PyObject *args)
|
||||
|
@ -1025,6 +1059,8 @@ static PyMethodDef TestMethods[] = {
|
|||
{"unicode_asucs4", unicode_asucs4, METH_VARARGS},
|
||||
{"unicode_asutf8", unicode_asutf8, METH_VARARGS},
|
||||
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS},
|
||||
{"unicode_decodeutf8", unicode_decodeutf8, METH_VARARGS},
|
||||
{"unicode_decodeutf8stateful",unicode_decodeutf8stateful, METH_VARARGS},
|
||||
{"unicode_concat", unicode_concat, METH_VARARGS},
|
||||
{"unicode_splitlines", unicode_splitlines, METH_VARARGS},
|
||||
{"unicode_split", unicode_split, METH_VARARGS},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue