From 5a855ba4167c7fe3ca9117a7d7b854bba64b057f Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Mon, 22 Aug 2022 22:29:31 +0000 Subject: [PATCH] Decode: don't break on non-struct embed field --- unmarshaler.go | 5 ++++- unmarshaler_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/unmarshaler.go b/unmarshaler.go index 2c526e93..31339cf3 100644 --- a/unmarshaler.go +++ b/unmarshaler.go @@ -1211,7 +1211,10 @@ func forEachField(t reflect.Type, path []int, do func(name string, path []int)) if t2.Kind() == reflect.Pointer { t2 = t2.Elem() } - forEachField(t2, fieldPath, do) + + if t2.Kind() == reflect.Struct { + forEachField(t2, fieldPath, do) + } continue } diff --git a/unmarshaler_test.go b/unmarshaler_test.go index 43a334e3..88255d14 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -3288,3 +3288,16 @@ func TestUnmarshal_RecursiveTableArray(t *testing.T) { }) } } + +func TestUnmarshalEmbedNonString(t *testing.T) { + type Foo []byte + type doc struct { + Foo + } + + d := doc{} + + err := toml.Unmarshal([]byte(`foo = 'bar'`), &d) + require.NoError(t, err) + require.Nil(t, d.Foo) +}