JSON-Patch icon indicating copy to clipboard operation
JSON-Patch copied to clipboard

Incorrect patch on remove array item after changing its property

Open Pavek opened this issue 9 years ago • 1 comments

I think this is related to #65, that I openeed a while ago. But in this case the result is worse as patch is completely wrong. Here's the test case:

it('should generate valid patch on remove array item after changing its property', function() {
      obj = {arr: [{ lastName:"Einstein" }, {lastName:"123"}]};
      var observer = jsonpatch.observe(obj);

      // 2 changes!
      obj.arr[0].lastName = 'Some';
      obj.arr.splice(0, 1);

      patches = jsonpatch.generate(observer);
      expect(patches).toEqual([
        { op: 'remove', path: '/arr/0' }
      ]);
    });

Fails as: Expected [ ] to equal [ { op : 'remove', path : '/arr/0' } ].

Pavek avatar Jun 13 '15 14:06 Pavek

I can confirm this bug. I'm not sure it will be fixed in this library but I'm happy to direct you to its sister library JSONPatcherProxy which had this issue eariler and is fixed now. And JSONPatcherProxy is a tad faster and is synchronous.

@warpech can I close?

alshakero avatar Jun 02 '18 20:06 alshakero