Skip to content

Commit 0410363

Browse files
author
Guillaume Desvé
committed
Ensure an item is within the upper array boundaries before replacing it
1 parent 2990bb3 commit 0410363

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
@@ -602,6 +602,11 @@ def test_replace_oob(self):
602602
patch_obj = [ { "op": "replace", "path": "/foo/10", "value": 10} ]
603603
self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
604604

605+
def test_replace_oob_length(self):
606+
src = {"foo": [0, 1]}
607+
patch_obj = [ { "op": "replace", "path": "/foo/2", "value": 2} ]
608+
self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
609+
605610
def test_replace_missing(self):
606611
src = {"foo": 1}
607612
patch_obj = [ { "op": "replace", "path": "/bar", "value": 10} ]

0 commit comments

Comments
 (0)