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

Unexpected diff when comparing similar objects #4

Open
andreasfreier opened this issue Nov 29, 2023 · 1 comment
Open

Unexpected diff when comparing similar objects #4

andreasfreier opened this issue Nov 29, 2023 · 1 comment

Comments

@andreasfreier
Copy link

For the following two similar objects

a = [
  {key: 'a', value: '0'},
  {key: 'BUG', value: ''},
  {key: 'c', value: '1'},
  {key: 'd', value: '2'},
  {key: 'e', value: '3'},
  {key: 'f', value: '4'},
  {key: 'g', value: '5'},
  {key: 'BUG', value: ''}
]


b = [
  {key: 'a', value: '0'},
  {key: 'BUG', value: ''},
  {key: 'c', value: '1'},
  {key: 'd', value: '2'},
  {key: 'e', value: '3'},
  {key: 'f', value: '4'},
  {key: 'g', value: '5'},
  {key: 'BUG', value: ''}
]

JsonDiff.diff(a, b) returns the following diff

[{"op"=>"move", "from"=>"/7", "path"=>"/1"}, {"op"=>"move", "from"=>"/2", "path"=>"/7"}]

which is replacing the similar lines with each other.

Strangely, if we remove any of the a/c/d/e/f/g lines in both objects, the bug isn't there anymore, e.g.

a = [
  {key: 'BUG', value: ''},
  {key: 'c', value: '1'},
  {key: 'd', value: '2'},
  {key: 'e', value: '3'},
  {key: 'f', value: '4'},
  {key: 'g', value: '5'},
  {key: 'BUG', value: ''}
]


b = [
  {key: 'BUG', value: ''},
  {key: 'c', value: '1'},
  {key: 'd', value: '2'},
  {key: 'e', value: '3'},
  {key: 'f', value: '4'},
  {key: 'g', value: '5'},
  {key: 'BUG', value: ''}
]

JsonDiff.diff(a, b)
=> []
@andreasfreier
Copy link
Author

PS. Found with json-diff 0.4.1

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