1
0
mirror of https://github.com/django/django.git synced 2025-06-05 11:39:13 +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,7 +39,6 @@ class Serializer(PythonSerializer):
if self.options.get("indent"):
self.stream.write("\n")
self.stream.write("]")
if self.options.get("indent"):
self.stream.write("\n")
def end_object(self, obj):

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

@ -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',
)