Description
When you try to apply a remove operation inside an array, depending of the array size and the operations structure an exception can be thrown.
Let's imagine the following example: you have an object with an array
of 2 elements. If you try to remove first the element at index 0
and then the element at index 1
, the execution fails. Why? Because the operations are applied in a sequential order, so, first we remove the element of the index 0
, and we get the array with just one element inside, then we try to remove the element at index 1
and there are not elements at that position.
I have created a github simple project to show this with unit test.
The easy way to avoid this is to create the deletion operations in descentent order: first the greatest index and last the smallest index. But it would be nice to take this into account inside the json-patch library.