Skip to content

Instantly share code, notes, and snippets.

@sttts
Created October 25, 2019 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sttts/e4200e8a60fa92ffa0b4dbb31316cfdc to your computer and use it in GitHub Desktop.
Save sttts/e4200e8a60fa92ffa0b4dbb31316cfdc to your computer and use it in GitHub Desktop.
diff --git a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
index e06a478429..6826e5950d 100644
--- a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
+++ b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
@@ -19,11 +19,8 @@ package json
import (
"encoding/json"
"io"
- "strconv"
- "unsafe"
"github.com/ghodss/yaml"
- jsoniter "github.com/json-iterator/go"
"github.com/ugorji/go/codec"
"k8s.io/apimachinery/pkg/runtime"
@@ -69,79 +66,6 @@ type Serializer struct {
var _ runtime.Serializer = &Serializer{}
var _ recognizer.RecognizingDecoder = &Serializer{}
-func init() {
- // Force jsoniter to decode number to interface{} via ints, if possible.
- decodeNumberAsInt64IfPossible := func(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
- switch iter.WhatIsNext() {
- case jsoniter.NumberValue:
- var number json.Number
- iter.ReadVal(&number)
- i64, err := strconv.ParseInt(string(number), 10, 64)
- if err == nil {
- *(*interface{})(ptr) = i64
- return
- }
- f64, err := strconv.ParseFloat(string(number), 64)
- if err == nil {
- *(*interface{})(ptr) = f64
- return
- }
- default:
- // init depth, if needed
- if iter.Attachment == nil {
- iter.Attachment = int(1)
- }
-
- // remember current depth
- originalAttachment := iter.Attachment
-
- // increment depth before descending
- if i, ok := iter.Attachment.(int); ok {
- iter.Attachment = i + 1
- if i > 10000 {
- iter.ReportError("parse", "exceeded max depth")
- return
- }
- }
-
- *(*interface{})(ptr) = iter.Read()
-
- // restore current depth
- iter.Attachment = originalAttachment
- }
- }
- jsoniter.RegisterTypeDecoderFunc("interface {}", decodeNumberAsInt64IfPossible)
-}
-
-// CaseSensitiveJsonIterator returns a jsoniterator API that's configured to be
-// case-sensitive when unmarshalling, and otherwise compatible with
-// the encoding/json standard library.
-func CaseSensitiveJsonIterator() jsoniter.API {
- return jsoniter.Config{
- EscapeHTML: true,
- SortMapKeys: true,
- ValidateJsonRawMessage: true,
- CaseSensitive: true,
- }.Froze()
-}
-
-var caseSensitiveJsonIterator = CaseSensitiveJsonIterator()
-
-// gvkWithDefaults returns group kind and version defaulting from provided default
-func gvkWithDefaults(actual, defaultGVK schema.GroupVersionKind) schema.GroupVersionKind {
- if len(actual.Kind) == 0 {
- actual.Kind = defaultGVK.Kind
- }
- if len(actual.Version) == 0 && len(actual.Group) == 0 {
- actual.Group = defaultGVK.Group
- actual.Version = defaultGVK.Version
- }
- if len(actual.Version) == 0 && actual.Group == defaultGVK.Group {
- actual.Version = defaultGVK.Version
- }
- return actual
-}
-
// Decode attempts to convert the provided data into YAML or JSON, extract the stored schema kind, apply the provided default gvk, and then
// load that data into an object matching the desired schema kind or the provided into. If into is *runtime.Unknown, the raw data will be
// extracted and no decoding will be performed. If into is not registered with the typer, then the object will be straight decoded using
diff --git a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json_limit_test.go b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json_limit_test.go
index 0414ec8a7b..8214d293c6 100644
--- a/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json_limit_test.go
+++ b/vendor/k8s.io/kubernetes/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json_limit_test.go
@@ -123,7 +123,6 @@ func testcases() []testcase {
var decoders = map[string]func([]byte, interface{}) error{
"gojson": gojson.Unmarshal,
"utiljson": utiljson.Unmarshal,
- "jsoniter": CaseSensitiveJsonIterator().Unmarshal,
}
func TestJSONLimits(t *testing.T) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment