diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 0febbc8e82..e004508adc 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1555,8 +1555,8 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Comment": "v4.0.0-3-g36442dbdb58521", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Comment": "v4.1.0-11-gd4020504c68b6b", + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/exponent-io/jsonpath", diff --git a/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json index 5c303ad9b5..2a9790e4fe 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json @@ -372,7 +372,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/ghodss/yaml", diff --git a/staging/src/k8s.io/apimachinery/Godeps/Godeps.json b/staging/src/k8s.io/apimachinery/Godeps/Godeps.json index 52655ff968..ce90141c15 100644 --- a/staging/src/k8s.io/apimachinery/Godeps/Godeps.json +++ b/staging/src/k8s.io/apimachinery/Godeps/Godeps.json @@ -24,7 +24,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiserver/Godeps/Godeps.json index c3ee8cbccd..5e66542adc 100644 --- a/staging/src/k8s.io/apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiserver/Godeps/Godeps.json @@ -372,7 +372,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/ghodss/yaml", diff --git a/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json b/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json index 2f973b487d..2f48ea106e 100644 --- a/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json +++ b/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/client-go/Godeps/Godeps.json b/staging/src/k8s.io/client-go/Godeps/Godeps.json index 69318cbc89..963b5084c1 100644 --- a/staging/src/k8s.io/client-go/Godeps/Godeps.json +++ b/staging/src/k8s.io/client-go/Godeps/Godeps.json @@ -56,7 +56,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/csi-api/Godeps/Godeps.json b/staging/src/k8s.io/csi-api/Godeps/Godeps.json index 1218aa5cc2..09b584f212 100644 --- a/staging/src/k8s.io/csi-api/Godeps/Godeps.json +++ b/staging/src/k8s.io/csi-api/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json b/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json index bf8d2e1568..ba20fb5c17 100644 --- a/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json +++ b/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json @@ -96,7 +96,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/go-openapi/jsonpointer", diff --git a/staging/src/k8s.io/metrics/Godeps/Godeps.json b/staging/src/k8s.io/metrics/Godeps/Godeps.json index 80d6aa9b7c..59b1b7470d 100644 --- a/staging/src/k8s.io/metrics/Godeps/Godeps.json +++ b/staging/src/k8s.io/metrics/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/node-api/Godeps/Godeps.json b/staging/src/k8s.io/node-api/Godeps/Godeps.json index 945acb3adc..d3bbc82cda 100644 --- a/staging/src/k8s.io/node-api/Godeps/Godeps.json +++ b/staging/src/k8s.io/node-api/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json b/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json index b920ad905a..bdd07fa415 100644 --- a/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json @@ -88,7 +88,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/go-openapi/jsonpointer", diff --git a/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json b/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json index d881a452c5..4d1dcd3113 100644 --- a/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/staging/src/k8s.io/sample-controller/Godeps/Godeps.json b/staging/src/k8s.io/sample-controller/Godeps/Godeps.json index 9f77150d79..2d268b9c92 100644 --- a/staging/src/k8s.io/sample-controller/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-controller/Godeps/Godeps.json @@ -12,7 +12,7 @@ }, { "ImportPath": "github.com/evanphx/json-patch", - "Rev": "36442dbdb585210f8d5a1b45e67aa323c197d5c4" + "Rev": "d4020504c68b6bfa818032bedfb48e33e9638506" }, { "ImportPath": "github.com/gogo/protobuf/proto", diff --git a/vendor/github.com/evanphx/json-patch/README.md b/vendor/github.com/evanphx/json-patch/README.md index 13b90420ca..ad011b2fac 100644 --- a/vendor/github.com/evanphx/json-patch/README.md +++ b/vendor/github.com/evanphx/json-patch/README.md @@ -25,6 +25,23 @@ go get -u github.com/evanphx/json-patch * [Comparing JSON documents](#comparing-json-documents) * [Combine merge patches](#combine-merge-patches) + +# Configuration + +* There is a global configuration variable `jsonpatch.SupportNegativeIndices`. + This defaults to `true` and enables the non-standard practice of allowing + negative indices to mean indices starting at the end of an array. This + functionality can be disabled by setting `jsonpatch.SupportNegativeIndices = + false`. + +* There is a global configuration variable `jsonpatch.ArraySizeLimit`, which + limits the length of any array the patched object can have. It defaults to 0, + which means there is no limit. + +* There is a global configuration variable `jsonpatch.ArraySizeAdditionLimit`, + which limits the increase of array length caused by each operation. It + defaults to 0, which means there is no limit. + ## Create and apply a merge patch Given both an original JSON document and a modified JSON document, you can create a [Merge Patch](https://tools.ietf.org/html/rfc7396) document. diff --git a/vendor/github.com/evanphx/json-patch/patch.go b/vendor/github.com/evanphx/json-patch/patch.go index 3d76e9e38b..b1ec06ae17 100644 --- a/vendor/github.com/evanphx/json-patch/patch.go +++ b/vendor/github.com/evanphx/json-patch/patch.go @@ -14,6 +14,10 @@ const ( eAry ) +var SupportNegativeIndices bool = true +var ArraySizeLimit int = 0 +var ArraySizeAdditionLimit int = 0 + type lazyNode struct { raw *json.RawMessage doc partialDoc @@ -61,6 +65,19 @@ func (n *lazyNode) UnmarshalJSON(data []byte) error { return nil } +func deepCopy(src *lazyNode) (*lazyNode, error) { + if src == nil { + return nil, nil + } + a, err := src.MarshalJSON() + if err != nil { + return nil, err + } + ra := make(json.RawMessage, len(a)) + copy(ra, a) + return newLazyNode(&ra), nil +} + func (n *lazyNode) intoDoc() (*partialDoc, error) { if n.which == eDoc { return &n.doc, nil @@ -354,10 +371,19 @@ func (d *partialArray) set(key string, val *lazyNode) error { } sz := len(*d) + + if diff := idx + 1 - sz; ArraySizeAdditionLimit > 0 && diff > ArraySizeAdditionLimit { + return fmt.Errorf("Unable to increase the array size by %d, the limit is %d", diff, ArraySizeAdditionLimit) + } + if idx+1 > sz { sz = idx + 1 } + if ArraySizeLimit > 0 && sz > ArraySizeLimit { + return fmt.Errorf("Unable to create array of size %d, limit is %d", sz, ArraySizeLimit) + } + ary := make([]*lazyNode, sz) cur := *d @@ -385,17 +411,29 @@ func (d *partialArray) add(key string, val *lazyNode) error { return err } - ary := make([]*lazyNode, len(*d)+1) + sz := len(*d) + 1 + if ArraySizeLimit > 0 && sz > ArraySizeLimit { + return fmt.Errorf("Unable to create array of size %d, limit is %d", sz, ArraySizeLimit) + } + + ary := make([]*lazyNode, sz) cur := *d - if idx < -len(ary) || idx >= len(ary) { + if idx >= len(ary) { return fmt.Errorf("Unable to access invalid index: %d", idx) } - if idx < 0 { - idx += len(ary) + if SupportNegativeIndices { + if idx < -len(ary) { + return fmt.Errorf("Unable to access invalid index: %d", idx) + } + + if idx < 0 { + idx += len(ary) + } } + copy(ary[0:idx], cur[0:idx]) ary[idx] = val copy(ary[idx+1:], cur[idx:]) @@ -426,11 +464,18 @@ func (d *partialArray) remove(key string) error { cur := *d - if idx < -len(cur) || idx >= len(cur) { - return fmt.Errorf("Unable to remove invalid index: %d", idx) + if idx >= len(cur) { + return fmt.Errorf("Unable to access invalid index: %d", idx) } - if idx < 0 { - idx += len(cur) + + if SupportNegativeIndices { + if idx < -len(cur) { + return fmt.Errorf("Unable to access invalid index: %d", idx) + } + + if idx < 0 { + idx += len(cur) + } } ary := make([]*lazyNode, len(cur)-1) @@ -567,7 +612,12 @@ func (p Patch) copy(doc *container, op operation) error { return fmt.Errorf("jsonpatch copy operation does not apply: doc is missing destination path: %s", path) } - return con.set(key, val) + valCopy, err := deepCopy(val) + if err != nil { + return err + } + + return con.add(key, valCopy) } // Equal indicates if 2 JSON documents have the same structural equality.