diff --git a/decode_hooks.go b/decode_hooks.go index 92e6f76f..5d871df1 100644 --- a/decode_hooks.go +++ b/decode_hooks.go @@ -63,6 +63,11 @@ func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc { return func(f reflect.Value, t reflect.Value) (interface{}, error) { var err error var data interface{} + + if len(fs) == 0 { + data = f.Interface() + } + newFrom := f for _, f1 := range fs { data, err = DecodeHookExec(f1, newFrom, t) diff --git a/decode_hooks_test.go b/decode_hooks_test.go index b3165bc9..cfa3c180 100644 --- a/decode_hooks_test.go +++ b/decode_hooks_test.go @@ -84,6 +84,38 @@ func TestComposeDecodeHookFunc_kinds(t *testing.T) { } } +func TestComposeDecodeHookFunc_safe_nofuncs(t *testing.T) { + f := ComposeDecodeHookFunc() + type myStruct2 struct { + MyInt int + } + + type myStruct1 struct { + Blah map[string]myStruct2 + } + + src := &myStruct1{Blah: map[string]myStruct2{ + "test": { + MyInt: 1, + }, + }} + + dst := &myStruct1{} + dConf := &DecoderConfig{ + Result: dst, + ErrorUnused: true, + DecodeHook: f, + } + d, err := NewDecoder(dConf) + if err != nil { + t.Fatal(err) + } + err = d.Decode(src) + if err != nil { + t.Fatal(err) + } +} + func TestStringToSliceHookFunc(t *testing.T) { f := StringToSliceHookFunc(",")