stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
459 stars 97 forks source link

Ensure an item is within the upper array boundaries before replacing it #96

Closed gdraynz closed 4 years ago

gdraynz commented 5 years ago

This will avoid an exception when trying to replace the item at the last position of an array:

ERROR: test_replace_oob_length (tests.ConflictTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/guillaume/src/jsonpatch/tests.py", line 608, in test_replace_oob_length
    self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
  File "/home/linuxbrew/.linuxbrew/var/pyenv/versions/3.7/lib/python3.7/unittest/case.py", line 743, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "/home/linuxbrew/.linuxbrew/var/pyenv/versions/3.7/lib/python3.7/unittest/case.py", line 178, in handle
    callable_obj(*args, **kwargs)
  File "/home/guillaume/src/jsonpatch/jsonpatch.py", line 143, in apply_patch
    return patch.apply(doc, in_place)
  File "/home/guillaume/src/jsonpatch/jsonpatch.py", line 312, in apply
    obj = operation.apply(obj)
  File "/home/guillaume/src/jsonpatch/jsonpatch.py", line 490, in apply
    subobj[part] = value
IndexError: list assignment index out of range

----------------------------------------------------------------------
stefankoegl commented 4 years ago

Thanks! I have just released v1.25 with this fix.