Skip to content

Commit

Permalink
Fix the converts an empty string to nil.
Browse files Browse the repository at this point in the history
Kubernetes-commit: 9759fc3c2306c5a82998899ffb189c381145199a
  • Loading branch information
HirazawaUi authored and k8s-publishing-bot committed Jul 11, 2023
1 parent 83d6d37 commit f3f45bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/runtime/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (c *fromUnstructuredContext) pushKey(key string) {

}

// FromUnstructuredWIthValidation converts an object from map[string]interface{} representation into a concrete type.
// FromUnstructuredWithValidation converts an object from map[string]interface{} representation into a concrete type.
// It uses encoding/json/Unmarshaler if object implements it or reflection if not.
// It takes a validationDirective that indicates how to behave when it encounters unknown fields.
func (c *unstructuredConverter) FromUnstructuredWithValidation(u map[string]interface{}, obj interface{}, returnUnknownFields bool) error {
Expand Down Expand Up @@ -465,7 +465,7 @@ func sliceFromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) e
}
dv.SetBytes(data)
} else {
dv.Set(reflect.Zero(dt))
dv.Set(reflect.MakeSlice(dt, 0, 0))
}
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/runtime/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type F struct {
G []int `json:"fg"`
H []bool `json:"fh"`
I []float32 `json:"fi"`
J []byte `json:"fj"`
}

type G struct {
Expand Down Expand Up @@ -751,6 +752,10 @@ func TestUnrecognized(t *testing.T) {
data: "{\"ff\":[\"abc\"],\"fg\":[123],\"fh\":[true,false]}",
obj: &F{},
},
{
data: "{\"fj\":\"\"}",
obj: &F{},
},
{
// Invalid string data
data: "{\"fa\":123}",
Expand Down

0 comments on commit f3f45bf

Please sign in to comment.