Skip to content

Commit f3f45bf

Browse files
HirazawaUik8s-publishing-bot
authored andcommitted
Fix the converts an empty string to nil.
Kubernetes-commit: 9759fc3c2306c5a82998899ffb189c381145199a
1 parent 83d6d37 commit f3f45bf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/runtime/converter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (c *fromUnstructuredContext) pushKey(key string) {
231231

232232
}
233233

234-
// FromUnstructuredWIthValidation converts an object from map[string]interface{} representation into a concrete type.
234+
// FromUnstructuredWithValidation converts an object from map[string]interface{} representation into a concrete type.
235235
// It uses encoding/json/Unmarshaler if object implements it or reflection if not.
236236
// It takes a validationDirective that indicates how to behave when it encounters unknown fields.
237237
func (c *unstructuredConverter) FromUnstructuredWithValidation(u map[string]interface{}, obj interface{}, returnUnknownFields bool) error {
@@ -465,7 +465,7 @@ func sliceFromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) e
465465
}
466466
dv.SetBytes(data)
467467
} else {
468-
dv.Set(reflect.Zero(dt))
468+
dv.Set(reflect.MakeSlice(dt, 0, 0))
469469
}
470470
return nil
471471
}

pkg/runtime/converter_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type F struct {
9191
G []int `json:"fg"`
9292
H []bool `json:"fh"`
9393
I []float32 `json:"fi"`
94+
J []byte `json:"fj"`
9495
}
9596

9697
type G struct {
@@ -751,6 +752,10 @@ func TestUnrecognized(t *testing.T) {
751752
data: "{\"ff\":[\"abc\"],\"fg\":[123],\"fh\":[true,false]}",
752753
obj: &F{},
753754
},
755+
{
756+
data: "{\"fj\":\"\"}",
757+
obj: &F{},
758+
},
754759
{
755760
// Invalid string data
756761
data: "{\"fa\":123}",

0 commit comments

Comments
 (0)