Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 28, 2020

Conversation

gdraynz
Copy link
Contributor

@gdraynz gdraynz commented May 16, 2019

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 stefankoegl merged commit b3726f3 into stefankoegl:master Jan 28, 2020
@stefankoegl
Copy link
Owner

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

@gdraynz gdraynz deleted the replace-array-indexerror branch January 29, 2020 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants