Skip to content

Commit

Permalink
fix(mapping): call fillSliceValue panic if the value is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
wuqinqiang authored and kevwan committed Jan 13, 2024
1 parent 81d72b5 commit 11259d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/mapping/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.

func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
baseKind reflect.Kind, value any, fullName string) error {
if value == nil {
return errUnsupportedType
}
ithVal := slice.Index(index)
switch v := value.(type) {
case fmt.Stringer:
Expand Down
14 changes: 14 additions & 0 deletions core/mapping/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
var v struct {
Ages []int `key:"ages"`
Expand Down

0 comments on commit 11259d8

Please sign in to comment.