Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions decode_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
}
return func(f reflect.Value, t reflect.Value) (any, error) {
var err error

if f.Kind() == reflect.Interface && f.IsNil() {
return nil, nil
}

data := f.Interface()

newFrom := f
Expand Down
27 changes: 27 additions & 0 deletions decode_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ func TestComposeDecodeHookFunc(t *testing.T) {
}
}

func TestComposeDecodeHookFuncNil(t *testing.T) {
f1 := func(
f reflect.Kind,
t reflect.Kind,
data any,
) (any, error) {
return data, nil
}

f2 := func(
f reflect.Kind,
t reflect.Kind,
data any,
) (any, error) {
return data, nil
}

f := ComposeDecodeHookFunc(f1, f2)

result, err := DecodeHookExec(
f, reflect.ValueOf(new(any)).Elem(), reflect.Value{})
if err != nil {
t.Fatalf("bad: %s", err)
}
_ = result
}

func TestComposeDecodeHookFunc_err(t *testing.T) {
f1 := func(reflect.Kind, reflect.Kind, any) (any, error) {
return nil, errors.New("foo")
Expand Down