fix(mapping): call fillSliceValue panic if the value is nil (#3839)
This commit is contained in:
@@ -249,6 +249,9 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
|||||||
|
|
||||||
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
||||||
baseKind reflect.Kind, value any, fullName string) error {
|
baseKind reflect.Kind, value any, fullName string) error {
|
||||||
|
if value == nil {
|
||||||
|
return errUnsupportedType
|
||||||
|
}
|
||||||
ithVal := slice.Index(index)
|
ithVal := slice.Index(index)
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case fmt.Stringer:
|
case fmt.Stringer:
|
||||||
|
|||||||
@@ -1329,6 +1329,20 @@ func TestUnmarshalInt64Slice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalNullableSlice(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
Ages []int64 `key:"ages"`
|
||||||
|
Slice []int8 `key:"slice"`
|
||||||
|
}
|
||||||
|
m := map[string]any{
|
||||||
|
"ages": []int64{1, 2},
|
||||||
|
"slice": `[null,2]`,
|
||||||
|
}
|
||||||
|
|
||||||
|
ast := assert.New(t)
|
||||||
|
ast.Equal(UnmarshalKey(m, &v), errUnsupportedType)
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnmarshalIntSlice(t *testing.T) {
|
func TestUnmarshalIntSlice(t *testing.T) {
|
||||||
var v struct {
|
var v struct {
|
||||||
Ages []int `key:"ages"`
|
Ages []int `key:"ages"`
|
||||||
|
|||||||
Reference in New Issue
Block a user