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

Wrong patch when substituting an object for an array? #31

Closed
maca opened this issue May 28, 2014 · 3 comments
Closed

Wrong patch when substituting an object for an array? #31

maca opened this issue May 28, 2014 · 3 comments
Assignees
Labels

Comments

@maca
Copy link

maca commented May 28, 2014

> jsonpatch.compare({a: {}}, {a: [1]});
[{op: "add", path: "/a/0", value: 1}]

Shouldn't be the empty object replaced with the array? the value is no longer an object.

[{op: "replace", path: "/a", value: [1]}]
@jamesplease
Copy link
Contributor

The same thing happens in reverse, too.

var x = jsonpatch.compare(['jack'], {});

// no good
x === [{
  op: "remove"
  path: "/0"
}];

and for an even bigger hint at what the issue is:

var x = jsonpatch.compare([], {});
x === [];

Deep down this library thinks that arrays and objects are the same thing! This likely stems from the fact that it only worries about the keys, which fails to differentiate arrays and objects in these edge cases.

@jamesplease
Copy link
Contributor

@Starcounter-Jack @warpech are either of you around? I'll make up a PR sooner rather than later if you'll have time to review it.

@alshakero
Copy link
Collaborator

Will be fixed in #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants