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

Generated patch incorrect for Array replacement #7

Open
tamalsaha opened this issue Aug 21, 2017 · 0 comments
Open

Generated patch incorrect for Array replacement #7

tamalsaha opened this issue Aug 21, 2017 · 0 comments

Comments

@tamalsaha
Copy link

Thanks for this handy library. I am trying to generate JSON patch . Here is a case that produces buggy patch:

src = {
  "spec": {
    "loadBalancerSourceRanges": [
      "192.101.0.0/16",
      "192.0.0.0/24"
    ]
  }
}

dst = {
  "spec": {
    "loadBalancerSourceRanges": [
      "192.101.0.0/24"
    ]
  }
}

The generated patch is:

[
  {
    "op": "remove",
    "path": "/spec/loadBalancerSourceRanges/0"
  },  
  {
    "op": "remove",
    "path": "/spec/loadBalancerSourceRanges/1"
  },
  {
    "op": "add",
    "path": "/spec/loadBalancerSourceRanges/0",
    "value": "192.101.0.0/24"
  }
]

This results in an error. The problem seems to be that index 1 should be removed before index 0. If I reverse the order the generated patch works.

I tested patch generation using https://github.com/stefankoegl/python-json-patch library . This produces a valid patch:

[{"path": "/spec/loadBalancerSourceRanges/1", "op": "remove"}, {"path": "/spec/loadBalancerSourceRanges/0", "value": "192.101.0.0/24", "op": "replace"}]

https://gist.github.com/tamalsaha/e8b313aec8f8d8191bc01ba504247e30

I also tested against a node.js library here: https://json8.github.io/patch/demos/apply/ . I get the same issue.

I wonder if you can fix this or give us pointers on how to fix this.

tamalsaha added a commit to kmodules/client-go that referenced this issue Aug 22, 2017
Our forked version fixes array comparison bug: mattbaird/jsonpatch#7
tamalsaha added a commit to kmodules/client-go that referenced this issue Aug 22, 2017
Our forked version fixes array comparison bug: mattbaird/jsonpatch#7
tamalsaha added a commit to kmodules/client-go that referenced this issue Aug 22, 2017
Our forked version fixes array comparison bug: mattbaird/jsonpatch#7
@tamalsaha tamalsaha reopened this Mar 3, 2018
e-nikolov pushed a commit to e-nikolov/jsonpatch that referenced this issue May 17, 2019
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

Successfully merging a pull request may close this issue.

1 participant