Skip to content

Commit b3726f3

Browse files
authored
Merge pull request #96 from gdraynz/replace-array-indexerror
Ensure an item is within the upper array boundaries before replacing it
2 parents 3e44e04 + 0410363 commit b3726f3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

jsonpatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def apply(self, obj):
474474
return value
475475

476476
if isinstance(subobj, MutableSequence):
477-
if part > len(subobj) or part < 0:
477+
if part >= len(subobj) or part < 0:
478478
raise JsonPatchConflict("can't replace outside of list")
479479

480480
elif isinstance(subobj, MutableMapping):

tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ def test_replace_oob(self):
611611
patch_obj = [ { "op": "replace", "path": "/foo/10", "value": 10} ]
612612
self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
613613

614+
def test_replace_oob_length(self):
615+
src = {"foo": [0, 1]}
616+
patch_obj = [ { "op": "replace", "path": "/foo/2", "value": 2} ]
617+
self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
618+
614619
def test_replace_missing(self):
615620
src = {"foo": 1}
616621
patch_obj = [ { "op": "replace", "path": "/bar", "value": 10} ]

0 commit comments

Comments
 (0)