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

Incorrect diff when first item of array changed #30

Open
jkomoros opened this issue Oct 7, 2018 · 0 comments
Open

Incorrect diff when first item of array changed #30

jkomoros opened this issue Oct 7, 2018 · 0 comments

Comments

@jkomoros
Copy link

jkomoros commented Oct 7, 2018

I ran into a case where the diff output appears to be incorrect. What follows is a reduced test case.

Contents of left.json:

{
	"Indexes":[
	    2,
	    -1,
	    1
	]
}

Contents of right.json:

{
	"Indexes":[
          -1,
          -1,
          -1
	]
}

Run the following:

jd -f delta left.json right.json > patch.json
jp patch.json left.json > derived_right.json
jd -f delta right.json derived_right.json

(That is, create a diff, then validate that applying the diff to the left input produces the right output.)

Expected output:

{}

(That is, the diff successfully creates right.json)

Actual output:

{
  "Indexes": {
    "_0": [
      -1,
      0,
      0
    ],
    "_t": "a"
  }
}

(That is, derived_right.json is different from right.json)

If you inspect dervied_right.json you see:

{
  "Indexes": [
    -1,
    -1
  ]
}

(That is, derived_right.json is missing one row)

I originally came across this with a much larger json diff, but reduced to this test case with trial and error. Oddly enough, the behavior appears to rely on the values of the integer constants in the left.json. For example, if you flip the position of 2 and 1 in left.json, it works as expected.

Note that I also was seeing similar behavior for an array that was not integer constants, but strings that went from "somevalue" to "" if they were in the first position in the array. I factored them out of the test case because the integer test case still triggered.

I think that the original jsondiffpatch works correctly in this case, at least based on using the webapp version: https://benjamine.github.io/jsondiffpatch/demo/index.html

I'm using the 0.0.2 version of the jd tool

Apologies if I'm missing something obvious or not using this as intended!

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