aogriffiths / jsondiff-js

A JavaScript implementation to create json patches of the JSON Media Type for partial modifications: http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08. See also https://github.com/bruth/jsonpatch-js.
https://github.com/aogriffiths/jsondiff-js
BSD 2-Clause "Simplified" License
23 stars 11 forks source link

Multiple remove operations use incorrect indices #4

Open Yaytay opened 10 years ago

Yaytay commented 10 years ago

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

andreas-gruenbacher commented 10 years ago

This bug is still there after four months. @aogriffiths: do you still care about this project?