Skip to content

Commit cfd69e5

Browse files
authored
Merge pull request #77 from ostackbrian/issue-76
Remove extraneous 'value' field for op:remove (#76)
2 parents df0c56d + e500b4d commit cfd69e5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

jsonpatch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ def _item_removed(self, path, key, item):
730730
new_op = RemoveOperation({
731731
'op': 'remove',
732732
'path': _path_join(path, key),
733-
'value': item,
734733
})
735734
index = self.take_index(item, _ST_ADD)
736735
new_index = self.insert(new_op)

tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ def test_issue40(self):
368368
dest = [7, 2, 1, 0, 9, 4, 3, 6, 5, 8]
369369
patch = jsonpatch.make_patch(src, dest)
370370

371+
def test_issue76(self):
372+
""" Make sure op:remove does not include a 'value' field """
373+
374+
src = { "name": "fred", "friend": "barney", "spouse": "wilma" }
375+
dst = { "name": "fred", "spouse": "wilma" }
376+
expected = [{"path": "/friend", "op": "remove"}]
377+
patch = jsonpatch.make_patch(src, dst)
378+
self.assertEqual(patch.patch, expected)
379+
res = jsonpatch.apply_patch(src, patch)
380+
self.assertEqual(res, dst)
381+
371382
def test_json_patch(self):
372383
old = {
373384
'queue': {'teams_out': [{'id': 3, 'reason': 'If tied'}, {'id': 5, 'reason': 'If tied'}]},
@@ -424,7 +435,7 @@ def test_use_replace_instead_of_remove_add_nested(self):
424435
dst = {'foo': [{'bar': 1}, {'bar': 2, 'baz': 3}]}
425436
patch = list(jsonpatch.make_patch(src, dst))
426437

427-
exp = [{'op': 'remove', 'value': 2, 'path': '/foo/0/baz'}]
438+
exp = [{'op': 'remove', 'path': '/foo/0/baz'}]
428439
self.assertEqual(patch, exp)
429440

430441
res = jsonpatch.apply_patch(src, patch)
@@ -481,11 +492,14 @@ def test_success_if_correct_expected_patch_appied(self):
481492
src = [{"a": 1, "b": 2}]
482493
dst = [{"b": 2, "c": 2}]
483494
exp = [
484-
{'path': '/0/a', 'op': 'remove', 'value': 1},
495+
{'path': '/0/a', 'op': 'remove'},
485496
{'path': '/0/c', 'op': 'add', 'value': 2}
486497
]
487498
patch = jsonpatch.make_patch(src, dst)
488499
self.assertEqual(patch.patch, exp)
500+
# verify that this patch does what we expect
501+
res = jsonpatch.apply_patch(src, patch)
502+
self.assertEqual(res, dst)
489503

490504
def test_minimal_patch(self):
491505
""" Test whether a minimal patch is created, see #36 """

0 commit comments

Comments
 (0)