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

JsonDiff bug found #163

Open
fmoghaddam opened this issue Oct 1, 2024 · 0 comments
Open

JsonDiff bug found #163

fmoghaddam opened this issue Oct 1, 2024 · 0 comments

Comments

@fmoghaddam
Copy link

Consider the following Jsons:

Source:

{
    "store": {
        "a": [
            "v1",
            "v2"
        ]
    }
}

Target:

{
    "store": {
        "a": []
    }
}

running JsonDiff.asJson(source, target) returns:

[ {
  "op" : "remove",
  "path" : "/store/a/0"
}, {
  "op" : "remove",
  "path" : "/store/a/0"
} ]

which as it is seen both path is same but actually the next path should be "/store/a/1". The reason is there is a bug in JsonDiff class in function generateArrayDiffs. There is a for loop as:

for(index = size; index < firstSize; ++index) {
   processor.valueRemoved(pointer.append(size), source.get(index));
}

Which should be changed to:

for(index = size; index < firstSize; ++index) {
   processor.valueRemoved(pointer.append(index), source.get(index));
}
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