JSON-Patch
JSON-Patch copied to clipboard
Incorrect patch on remove array item after changing its property
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' } ].
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?