mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.11] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224)
Previously *consumed was not set in this case.
(cherry picked from commit f08e52ccb0)
This commit is contained in:
parent
058741cc39
commit
b8b3e6afc0
4 changed files with 95 additions and 1 deletions
|
|
@ -2307,6 +2307,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);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
unicode_findchar(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -6562,7 +6596,8 @@ static PyMethodDef TestMethods[] = {
|
|||
{"unicode_asucs4", unicode_asucs4, METH_VARARGS},
|
||||
{"unicode_asutf8", unicode_asutf8, METH_VARARGS},
|
||||
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS},
|
||||
{"unicode_findchar", unicode_findchar, METH_VARARGS},
|
||||
{"unicode_decodeutf8", unicode_decodeutf8, METH_VARARGS},
|
||||
{"unicode_decodeutf8stateful",unicode_decodeutf8stateful, METH_VARARGS}, {"unicode_findchar", unicode_findchar, METH_VARARGS},
|
||||
{"unicode_copycharacters", unicode_copycharacters, METH_VARARGS},
|
||||
#if USE_UNICODE_WCHAR_CACHE
|
||||
{"unicode_legacy_string", unicode_legacy_string, METH_VARARGS},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue