mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
[3.14] gh-131884: Fix incorrect formatting in json.dumps() when using indent and skipkeys=True (GH-132200) (GH-135060)
(cherry picked from commit ec12559eba)
Co-authored-by: Roei Ben Artzi <155478676+roeibenartzi@users.noreply.github.com>
This commit is contained in:
parent
e11d4a18e1
commit
97822b8199
4 changed files with 20 additions and 7 deletions
|
|
@ -1609,6 +1609,12 @@ encoder_encode_key_value(PyEncoderObject *s, PyUnicodeWriter *writer, bool *firs
|
|||
|
||||
if (*first) {
|
||||
*first = false;
|
||||
if (s->indent != Py_None) {
|
||||
if (write_newline_indent(writer, indent_level, indent_cache) < 0) {
|
||||
Py_DECREF(keystr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (PyUnicodeWriter_WriteStr(writer, item_separator) < 0) {
|
||||
|
|
@ -1676,11 +1682,8 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
|
|||
if (s->indent != Py_None) {
|
||||
indent_level++;
|
||||
separator = get_item_separator(s, indent_level, indent_cache);
|
||||
if (separator == NULL ||
|
||||
write_newline_indent(writer, indent_level, indent_cache) < 0)
|
||||
{
|
||||
if (separator == NULL)
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
if (s->sort_keys || !PyDict_CheckExact(dct)) {
|
||||
|
|
@ -1720,7 +1723,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
|
|||
goto bail;
|
||||
Py_CLEAR(ident);
|
||||
}
|
||||
if (s->indent != Py_None) {
|
||||
if (s->indent != Py_None && !first) {
|
||||
indent_level--;
|
||||
if (write_newline_indent(writer, indent_level, indent_cache) < 0) {
|
||||
goto bail;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue