Skip to content

Commit a2e51fb

Browse files
committed
Fix make_patch() when root is an array (fixes #28)
1 parent 036045d commit a2e51fb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

jsonpatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def compare_dicts(path, src, dst):
308308
def compare_lists(path, src, dst):
309309
return _compare_lists(path, src, dst)
310310

311-
return cls(list(compare_dicts([], src, dst)))
311+
return cls(list(compare_values([], src, dst)))
312312

313313
def to_string(self):
314314
"""Returns patch set as JSON string."""

tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ def test_escape(self):
341341
res = patch.apply(src)
342342
self.assertEqual(res, dst)
343343

344+
def test_root_list(self):
345+
""" Test making and applying a patch of the root is a list """
346+
src = [{'foo': 'bar', 'boo': 'qux'}]
347+
dst = [{'baz': 'qux', 'foo': 'boo'}]
348+
patch = jsonpatch.make_patch(src, dst)
349+
res = patch.apply(src)
350+
self.assertEqual(res, dst)
351+
344352

345353
class InvalidInputTests(unittest.TestCase):
346354

0 commit comments

Comments
 (0)