cujojs / jiff

JSON Patch and diff based on rfc6902
Other
627 stars 41 forks source link

Fix coalesce adjacent remove + add into replace #40

Closed manishbhatias closed 4 years ago

manishbhatias commented 4 years ago

Comparision of path for adjacent add + remove operation was broken when offset functionality was introduced

Test case

let jif = require('jiff');
let a = [1,2,3];
let b = [4,2,3];
console.log(jif.diff(a, b, {invertible:false}));

Result

Array (2 items)
0: Object {context: undefined, op: "add", path: "/0", value: 4}
1: Object {context: undefined, op: "remove", path: "/1"}

Expected Result

Array (1 item)
0: Object {context: undefined, op: "replace", path: "/0", value: 4}

Signed-off-by: Manish Bhatia manish@giveindia.org

briancavalier commented 4 years ago

Hi @manishbhatias, thanks for opening this PR! Could you also add a test case that shows the issue, i.e., a test that fails without your changes and passes with them. That'd be much appreciated.