diff --git a/decode_hooks.go b/decode_hooks.go index 3a754ca7..f4941ac5 100644 --- a/decode_hooks.go +++ b/decode_hooks.go @@ -103,10 +103,13 @@ func OrComposeDecodeHookFunc(ff ...DecodeHookFunc) DecodeHookFunc { // string to []string by splitting on the given sep. func StringToSliceHookFunc(sep string) DecodeHookFunc { return func( - f reflect.Kind, - t reflect.Kind, + f reflect.Type, + t reflect.Type, data interface{}) (interface{}, error) { - if f != reflect.String || t != reflect.Slice { + if f.Kind() != reflect.String { + return data, nil + } + if t != reflect.SliceOf(f) { return data, nil } diff --git a/decode_hooks_test.go b/decode_hooks_test.go index bf029526..0478a2bb 100644 --- a/decode_hooks_test.go +++ b/decode_hooks_test.go @@ -208,13 +208,13 @@ func TestStringToSliceHookFunc(t *testing.T) { f := StringToSliceHookFunc(",") strValue := reflect.ValueOf("42") - sliceValue := reflect.ValueOf([]byte("42")) + sliceValue := reflect.ValueOf([]string{"42"}) cases := []struct { f, t reflect.Value result interface{} err bool }{ - {sliceValue, sliceValue, []byte("42"), false}, + {sliceValue, sliceValue, []string{"42"}, false}, {strValue, strValue, "42", false}, { reflect.ValueOf("foo,bar,baz"),