Code

Ticket #13182: noTrailingWhitespace.diff

File noTrailingWhitespace.diff, 1.5 KB (added by martmatwarne, 11 months ago)
Line 
1diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
2index 64357bf..b0b88d5 100644
3--- a/django/core/serializers/json.py
4+++ b/django/core/serializers/json.py
5@@ -36,8 +36,6 @@ class Serializer(PythonSerializer):
6         if self.options.get("indent"):
7             self.stream.write("\n")
8         self.stream.write("]")
9-        if self.options.get("indent"):
10-            self.stream.write("\n")
11 
12     def end_object(self, obj):
13         # self._current has the field data
14diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
15index a96a1af..1bec907 100644
16--- a/tests/serializers/tests.py
17+++ b/tests/serializers/tests.py
18@@ -389,6 +389,34 @@ class JsonSerializerTestCase(SerializersTestBase, TestCase):
19                 ret_list.append(obj_dict["fields"][field_name])
20         return ret_list
21 
22+_json_expected="""[
23+{
24+  "pk": 1,
25+  "model": "serializers.score",
26+  "fields": {
27+    "score": 5.0
28+  }
29+},
30+{
31+  "pk": 2,
32+  "model": "serializers.score",
33+  "fields": {
34+    "score": 6.0
35+  }
36+}
37+]"""
38+
39+
40+class TestJsonSerializerIndentation(TestCase):
41+    def test_indentation_whitespace(self):
42+        from django.core.serializers.json import Serializer
43+        Score.objects.create(score=5.0)
44+        Score.objects.create(score=6.0)
45+        qset = Score.objects.all()
46+
47+        s = Serializer()
48+        self.assertEqual(s.serialize(qset, indent=2), _json_expected)
49+
50 class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
51     serializer_name = "json"
52     fwd_ref_str = """[