Skip to content

Multiple remove operations use incorrect indices #4

@Yaytay

Description

@Yaytay

Hi,

Given these two JSON objects:
{
"authorities": ["ROLE_ADMIN",
"ROLE_POWERUSER",
"ROLE_USER"],
"id": 2,
}

{
"authorities": ["ROLE_USER"],
"id": 2,
}

JSONdiff produces this patch:
[{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/2"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]

The problem is that, according to http://tools.ietf.org/html/rfc6902#page-6:
If removing an element from an array, any elements above the
specified index are shifted one position to the left.

So this should actually be:
[{"op":"remove","path":"/authorities/1"},{"op":"remove","path":"/authorities/1"},{"op":"replace","path":"/authorities/0","value":"ROLE_USER"}]

Removing number 1 twice.

It would, of course, also be valid to work in reverse and always remove from higher indices first.

Jim

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions