mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 21:36:24 +00:00
Merge pull request #119229 from HirazawaUi/fix-convert-slice
Fix the converts an empty string to nil.
This commit is contained in:
commit
95e915c428
@ -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 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.
|
// 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 {
|
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
|
|||||||
}
|
}
|
||||||
dv.SetBytes(data)
|
dv.SetBytes(data)
|
||||||
} else {
|
} else {
|
||||||
dv.Set(reflect.Zero(dt))
|
dv.Set(reflect.MakeSlice(dt, 0, 0))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ type F struct {
|
|||||||
G []int `json:"fg"`
|
G []int `json:"fg"`
|
||||||
H []bool `json:"fh"`
|
H []bool `json:"fh"`
|
||||||
I []float32 `json:"fi"`
|
I []float32 `json:"fi"`
|
||||||
|
J []byte `json:"fj"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type G struct {
|
type G struct {
|
||||||
@ -751,6 +752,10 @@ func TestUnrecognized(t *testing.T) {
|
|||||||
data: "{\"ff\":[\"abc\"],\"fg\":[123],\"fh\":[true,false]}",
|
data: "{\"ff\":[\"abc\"],\"fg\":[123],\"fh\":[true,false]}",
|
||||||
obj: &F{},
|
obj: &F{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
data: "{\"fj\":\"\"}",
|
||||||
|
obj: &F{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// Invalid string data
|
// Invalid string data
|
||||||
data: "{\"fa\":123}",
|
data: "{\"fa\":123}",
|
||||||
|
Loading…
Reference in New Issue
Block a user