I've received a report from my application's user that the returning data is wrong while reversing the diff by unpatch method. By using my whole day, I find that only a specific pattern of change will cause the issue. Here's the code to reproduce it:
const objectHash = (obj, idx) => obj._id || obj.id || `$$index: ${idx}`;
const diffPatcher = require('jsondiffpatch').create({ objectHash });
function makeDiff() {
const cusV0 = {
reportData: {
description: "This is the beginning textM & XX2 checked pulse and breathing. XXX initiated, XXX administered."
}
}
const cusV1 = {
reportData: {
description: "Making something new with ipsumProin aliquam eros in purus luctus, ut efficitur metus porttitor. Nulla id tempor tellus. Nulla a suscipit mi. Duis aliquet dictum dui, a lacinia arcu dictum non. Maecenas et efficitur nisi. Quisque in sapien tellus. Donec in nisl ex. Aliquam erat volutpat. Suspendisse quis felis leo. Vivamus a ultricies nisi, sed sagittis lectus. Phasellus semper sed magna sit amet tempus. Quisque sodales dapibus aliquam. Integer accumsan et velit vitae aliquam. Nullam dictum elit quis erat accumsan consectetur. Curabitur non diam condimentum, finibus metus et, tincidunt libero. M & XX2 NewGuy checked newword pulse and breathing at 7:13. Something new againVivamus finibus, sapien scelerisque fringilla bibendum, ipsum sapien placerat sapien, vulputate consectetur risus dui quis leo. Vivamus vehicula eget leo sed aliquam. Sed pulvinar mauris tempor, condimentum magna ut, eleifend est. Maecenas non felis placerat, consectetur dui vitae, ornare lorem. Pellentesque pretium dui id nisl tincidunt, id finibus felis interdum. Proin ornare, quam eget dictum convallis, lacus ex consequat neque, non imperdiet dolor dui vel mi. Donec ex neque, venenatis sed nulla sed, vulputate elementum purus. End of report."
}
}
let diff = diffPatcher.diff(
JSON.parse(JSON.stringify(cusV0)),
JSON.parse(JSON.stringify(cusV1))
);
console.log("Diff object:")
console.log(diff)
// console.log(diffV1)
// console.log(upd);
let unp = diffPatcher.unpatch(cusV1, diff);
console.log("Unpatched object:")
console.log(unp);
}
// unpatchDiff();
makeDiff();
Result:
Expected Result:
reportData: {
description: "This is the beginning textM & XX2 checked pulse and breathing. XXX initiated, XXX administered."
}
I've received a report from my application's user that the returning data is wrong while reversing the diff by
unpatch
method. By using my whole day, I find that only a specific pattern of change will cause the issue. Here's the code to reproduce it:Result:
Expected Result: