Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diff calculated wrong #3

Open
nebulaszlonemethi opened this issue Nov 10, 2017 · 1 comment
Open

diff calculated wrong #3

nebulaszlonemethi opened this issue Nov 10, 2017 · 1 comment

Comments

@nebulaszlonemethi
Copy link

In the simple example, a weird "copy" patch is calculated as a diff what is wrong. Check it on codepen or here:

var a = {
  choices: [
    {id: "2"}
  ]
};
var b = {
  choices: [
    {id: "2"}
  ],
  description: "2"
};

var diff = jdr.diff(a, b);
jdr.apply(a, diff, {OBJ_COM:false});

console.info("diff:", diff); // results [{op: "copy", path: "/description", from: "/choices/0"}]
console.info("this should be b:", a); // results something else than b
@nebulaszlonemethi
Copy link
Author

nebulaszlonemethi commented Nov 15, 2017

Ok, i think the problem is here (at least for my case): when you are building the unchanged array in transformArray(), you store hashes:

unchanged.push( path + '/' + y_sorted[j].index + "=" + JSON.stringify(x_sorted[i].hash));

Then, when you are searching in the unchanged array in generateObjectDiff(), you search for a simple value, not for hash:

var pointer = unchangedArea.findValueInUnchanged(JSON.stringify(newVal), unchanged);

so the pointer can be calculated wrong.

nlac added a commit to nlac/json_diff_rfc6902 that referenced this issue Jan 31, 2018
…ckage-lock.json)

- removed packaging itself as an external node module
- fixed async warning dropping by fs
- fixed issue caohanyang#3 (diff calculated wrong)
- modified expected test results where the calculated patch is equivalent (now only 1 fails)
- added comments to almost every change
- the code formatting is a mess, but i've left it as it is to compare more easy - proper tabulating required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant