From 43127316a38e18e1303faeec3c2c0463f3eaff58 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Wed, 7 Aug 2019 10:05:54 +0200 Subject: [PATCH] bumps evanphx/json-patch actually, those changes pin the library to the specific commit - the one that is required by k8s. --- glide.yaml | 2 +- .../github.com/evanphx/json-patch/README.md | 2 +- vendor/github.com/evanphx/json-patch/patch.go | 19 +++--- .../evanphx/json-patch/patch_test.go | 66 ++++++++++++++++++- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/glide.yaml b/glide.yaml index aae975825200..8b53c2fdfb68 100644 --- a/glide.yaml +++ b/glide.yaml @@ -300,7 +300,7 @@ import: - package: github.com/euank/go-kmsg-parser version: 5ba4d492e455a77d25dcf0d2c4acc9f2afebef4e - package: github.com/evanphx/json-patch - version: 94e38aa1586e8a6c8a75770bddf5ff84c48a106b + version: 5858425f75500d40c52783dce87d085a483ce135 - package: github.com/exponent-io/jsonpath version: d6023ce2651d8eafb5c75bb0c7167536102ec9f5 - package: github.com/fatih/camelcase diff --git a/vendor/github.com/evanphx/json-patch/README.md b/vendor/github.com/evanphx/json-patch/README.md index 986460aa31e5..9c7f87f7ceaa 100644 --- a/vendor/github.com/evanphx/json-patch/README.md +++ b/vendor/github.com/evanphx/json-patch/README.md @@ -15,7 +15,7 @@ go get -u github.com/evanphx/json-patch ``` **Stable Versions**: -* Version 3: `go get -u gopkg.in/evanphx/json-patch.v3` +* Version 4: `go get -u gopkg.in/evanphx/json-patch.v4` (previous versions below `v3` are unavailable) diff --git a/vendor/github.com/evanphx/json-patch/patch.go b/vendor/github.com/evanphx/json-patch/patch.go index b78322a088e6..c9cf590216c3 100644 --- a/vendor/github.com/evanphx/json-patch/patch.go +++ b/vendor/github.com/evanphx/json-patch/patch.go @@ -228,7 +228,7 @@ func (n *lazyNode) equal(o *lazyNode) bool { } func (o operation) kind() string { - if obj, ok := o["op"]; ok { + if obj, ok := o["op"]; ok && obj != nil { var op string err := json.Unmarshal(*obj, &op) @@ -244,7 +244,7 @@ func (o operation) kind() string { } func (o operation) path() string { - if obj, ok := o["path"]; ok { + if obj, ok := o["path"]; ok && obj != nil { var op string err := json.Unmarshal(*obj, &op) @@ -260,7 +260,7 @@ func (o operation) path() string { } func (o operation) from() string { - if obj, ok := o["from"]; ok { + if obj, ok := o["from"]; ok && obj != nil { var op string err := json.Unmarshal(*obj, &op) @@ -402,10 +402,9 @@ func (d *partialArray) add(key string, val *lazyNode) error { if idx < -len(ary) { return fmt.Errorf("Unable to access invalid index: %d", idx) } - idx = len(ary) - idx + if idx < 0 { idx += len(ary) - return fmt.Errorf("Unable to access invalid index: %d", idx) } } @@ -469,7 +468,7 @@ func (p Patch) add(doc *container, op operation) error { con, key := findObject(doc, path) if con == nil { - return fmt.Errorf("jsonpatch add operation does not apply: doc is missing path: %s", path) + return fmt.Errorf("jsonpatch add operation does not apply: doc is missing path: \"%s\"", path) } return con.add(key, op.value()) @@ -481,7 +480,7 @@ func (p Patch) remove(doc *container, op operation) error { con, key := findObject(doc, path) if con == nil { - return fmt.Errorf("jsonpatch remove operation does not apply: doc is missing path: %s", path) + return fmt.Errorf("jsonpatch remove operation does not apply: doc is missing path: \"%s\"", path) } return con.remove(key) @@ -496,8 +495,8 @@ func (p Patch) replace(doc *container, op operation) error { return fmt.Errorf("jsonpatch replace operation does not apply: doc is missing path: %s", path) } - val, ok := con.get(key) - if val == nil || ok != nil { + _, ok := con.get(key) + if ok != nil { return fmt.Errorf("jsonpatch replace operation does not apply: doc is missing key: %s", path) } @@ -554,6 +553,8 @@ func (p Patch) test(doc *container, op operation) error { return nil } return fmt.Errorf("Testing value %s failed", path) + } else if op.value() == nil { + return fmt.Errorf("Testing value %s failed", path) } if val.equal(op.value()) { diff --git a/vendor/github.com/evanphx/json-patch/patch_test.go b/vendor/github.com/evanphx/json-patch/patch_test.go index 96c531803401..9de5a089be25 100644 --- a/vendor/github.com/evanphx/json-patch/patch_test.go +++ b/vendor/github.com/evanphx/json-patch/patch_test.go @@ -126,6 +126,11 @@ var Cases = []Case{ `[ { "op": "move", "from": "/foo/1", "path": "/foo/2" } ]`, `{ "foo": [ "all", "cows", "grass", "eat" ] }`, }, + { + `{ "foo": [ "a", "b", "c", "d", "e" ] }`, + `[ { "op": "move", "from": "/foo/1", "path": "/foo/2" } ]`, + `{ "foo": [ "a", "c", "b", "d", "e" ] }`, + }, { `{ "foo": "bar" }`, `[ { "op": "add", "path": "/child", "value": { "grandchild": { } } } ]`, @@ -186,6 +191,36 @@ var Cases = []Case{ `[{"op": "copy", "path": "/foo/0", "from": "/foo"}]`, `{ "foo": [["bar"], "bar"]}`, }, + { + `{ "foo": ["bar","qux","baz"]}`, + `[ { "op": "remove", "path": "/foo/-2"}]`, + `{ "foo": ["bar", "baz"]}`, + }, + { + `{ "foo": []}`, + `[ { "op": "add", "path": "/foo/-1", "value": "qux"}]`, + `{ "foo": ["qux"]}`, + }, + { + `{ "bar": [{"baz": null}]}`, + `[ { "op": "replace", "path": "/bar/0/baz", "value": 1 } ]`, + `{ "bar": [{"baz": 1}]}`, + }, + { + `{ "bar": [{"baz": 1}]}`, + `[ { "op": "replace", "path": "/bar/0/baz", "value": null } ]`, + `{ "bar": [{"baz": null}]}`, + }, + { + `{ "bar": [null]}`, + `[ { "op": "replace", "path": "/bar/0", "value": 1 } ]`, + `{ "bar": [1]}`, + }, + { + `{ "bar": [1]}`, + `[ { "op": "replace", "path": "/bar/0", "value": null } ]`, + `{ "bar": [null]}`, + }, { fmt.Sprintf(`{ "foo": ["A", %q] }`, repeatedA(48)), // The wrapping quotes around 'A's are included in the copy @@ -248,7 +283,6 @@ var BadCases = []BadCase{ `{ "foo": ["bar","baz"]}`, `[ { "op": "add", "path": "/foo/-4", "value": "bum"}]`, }, - { `{ "name":{ "foo": "bat", "qux": "bum"}}`, `[ { "op": "replace", "path": "/foo/bar", "value":"baz"}]`, @@ -257,6 +291,30 @@ var BadCases = []BadCase{ `{ "foo": ["bar"]}`, `[ {"op": "add", "path": "/foo/2", "value": "bum"}]`, }, + { + `{ "foo": []}`, + `[ {"op": "remove", "path": "/foo/-"}]`, + }, + { + `{ "foo": []}`, + `[ {"op": "remove", "path": "/foo/-1"}]`, + }, + { + `{ "foo": ["bar"]}`, + `[ {"op": "remove", "path": "/foo/-2"}]`, + }, + { + `{}`, + `[ {"op":null,"path":""} ]`, + }, + { + `{}`, + `[ {"op":"add","path":null} ]`, + }, + { + `{}`, + `[ { "op": "copy", "from": null }]`, + }, { `{ "foo": ["bar"]}`, `[{"op": "copy", "path": "/foo/6666666666", "from": "/"}]`, @@ -400,6 +458,12 @@ var TestCases = []TestCase{ true, "", }, + { + `{ "foo": [] }`, + `[ { "op": "test", "path": "/foo"} ]`, + false, + "/foo", + }, } func TestAllTest(t *testing.T) {