1
0
mirror of https://github.com/django/django.git synced 2025-04-13 03:52:20 +00:00

Fixed #36177 -- Added a trailing newline to JSON serializer. (#19232)

This commit is contained in:
Tom Carrick 2025-03-11 08:01:06 +01:00 committed by GitHub
parent ab148c02ce
commit 8df5ce80d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 23 additions and 27 deletions

View File

@ -18,11 +18,6 @@ max_line_length = 88
[*.html]
indent_size = 2
# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore
[**/admin/js/vendor/**]
indent_style = ignore
indent_size = ignore

View File

@ -39,8 +39,7 @@ class Serializer(PythonSerializer):
if self.options.get("indent"):
self.stream.write("\n")
self.stream.write("]")
if self.options.get("indent"):
self.stream.write("\n")
self.stream.write("\n")
def end_object(self, obj):
# self._current has the field data

View File

@ -293,7 +293,8 @@ of each library are the first to add or confirm compatibility with Python 3.12:
Miscellaneous
-------------
* ...
* The :ref:`JSON <serialization-formats-json>` serializer now writes a newline
at the end of the output, even without the ``indent`` option set.
.. _deprecated-features-6.0:

View File

@ -7,4 +7,4 @@
"pub_date": "2006-06-16 14:00:00"
}
}
]
]

View File

@ -7,4 +7,4 @@
"pub_date": "2006-06-16 14:00:00"
}
}
]
]

View File

@ -31,4 +31,4 @@
"title": "News Stories"
}
}
]
]

View File

@ -15,4 +15,4 @@
"pub_date": "2006-06-16 15:00:00"
}
}
]
]

View File

@ -6,4 +6,4 @@
"name": "Load Absolute Path Test"
}
}
]
]

View File

@ -80,4 +80,4 @@
"channels": [6]
}
}
]
]

View File

@ -1 +1 @@
[]
[]

View File

@ -14,4 +14,4 @@
"name": "Neal Stephenson"
}
}
]
]

View File

@ -14,4 +14,4 @@
"name": "Neal Stephenson"
}
}
]
]

View File

@ -22,4 +22,4 @@
"stores": [11]
}
}
]
]

View File

@ -9,4 +9,4 @@
"weight": 1.2
}
}
]
]

View File

@ -95,4 +95,4 @@
"poly" : "POLYGON ((-95.447918 29.727275, -95.447418 29.71003, -95.446918 29.69013, -95.454318 29.68893, -95.475819 29.68903, -95.475819 29.69113, -95.484419 29.69103, -95.484519 29.69903, -95.480419 29.70133, -95.480419 29.69833, -95.474119 29.69833, -95.474119 29.70453, -95.472719 29.71283, -95.468019 29.71293, -95.468219 29.720229, -95.464018 29.720229, -95.464118 29.724529, -95.463018 29.725929, -95.459818 29.726129, -95.459918 29.720329, -95.451418 29.720429, -95.451775 29.726303, -95.451318 29.727029, -95.447918 29.727275))"
}
}
]
]

View File

@ -31,4 +31,4 @@
"price": "100"
}
}
]
]

View File

@ -7,4 +7,4 @@
"published": "2009-7-8"
}
}
]
]

View File

@ -23,4 +23,4 @@
"editor": ["Chris Mills"]
}
}
]
]

View File

@ -15,4 +15,4 @@
"owner": 2
}
}
]
]

View File

@ -6,4 +6,4 @@
"name": "Elvis Presley"
}
}
]
]

View File

@ -489,7 +489,8 @@ class SerializerAPITests(SimpleTestCase):
self.assertIs(serializer.stream_class, File)
self.assertIsInstance(serializer.stream, File)
self.assertEqual(
data, '[{"model": "serializers.score", "pk": 1, "fields": {"score": 3.4}}]'
data,
'[{"model": "serializers.score", "pk": 1, "fields": {"score": 3.4}}]\n',
)

View File

@ -13,4 +13,4 @@
"name": "robert"
}
}
]
]