Skip to content

Unable to remove array elements in ascendent order #56

Open
@Trebolete

Description

@Trebolete

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions