diff options
-rw-r--r-- | jsonpatch.py | 2 | ||||
-rwxr-xr-x | tests.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 4f8a02b..1b90bfd 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -474,7 +474,7 @@ class ReplaceOperation(PatchOperation): return value if isinstance(subobj, MutableSequence): - if part > len(subobj) or part < 0: + if part >= len(subobj) or part < 0: raise JsonPatchConflict("can't replace outside of list") elif isinstance(subobj, MutableMapping): @@ -602,6 +602,11 @@ class ConflictTests(unittest.TestCase): patch_obj = [ { "op": "replace", "path": "/foo/10", "value": 10} ] self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj) + def test_replace_oob_length(self): + src = {"foo": [0, 1]} + patch_obj = [ { "op": "replace", "path": "/foo/2", "value": 2} ] + self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj) + def test_replace_missing(self): src = {"foo": 1} patch_obj = [ { "op": "replace", "path": "/bar", "value": 10} ] |