mirror of
https://github.com/python/cpython.git
synced 2025-10-05 22:51:56 +00:00
[3.6] bpo-31505: Fix an assertion failure in json, in case _json.make_encoder() received a bad encoder() argument. (GH-3643) (#3777)
(cherry picked from commit 2b382dd612
)
This commit is contained in:
parent
90fe25a051
commit
7c24e99c99
3 changed files with 36 additions and 3 deletions
|
@ -1431,10 +1431,20 @@ static PyObject *
|
|||
encoder_encode_string(PyEncoderObject *s, PyObject *obj)
|
||||
{
|
||||
/* Return the JSON representation of a string */
|
||||
if (s->fast_encode)
|
||||
PyObject *encoded;
|
||||
|
||||
if (s->fast_encode) {
|
||||
return s->fast_encode(NULL, obj);
|
||||
else
|
||||
return PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
|
||||
}
|
||||
encoded = PyObject_CallFunctionObjArgs(s->encoder, obj, NULL);
|
||||
if (encoded != NULL && !PyUnicode_Check(encoded)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"encoder() must return a string, not %.80s",
|
||||
Py_TYPE(encoded)->tp_name);
|
||||
Py_DECREF(encoded);
|
||||
return NULL;
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue