Decode: don't break on non-struct embed field (#810)

This commit is contained in:
Thomas Pelletier
2022-08-22 18:39:11 -04:00
committed by GitHub
parent 7d69e4a728
commit 28f1efc7d3
2 changed files with 17 additions and 1 deletions
+4 -1
View File
@@ -1211,7 +1211,10 @@ func forEachField(t reflect.Type, path []int, do func(name string, path []int))
if t2.Kind() == reflect.Pointer { if t2.Kind() == reflect.Pointer {
t2 = t2.Elem() t2 = t2.Elem()
} }
forEachField(t2, fieldPath, do)
if t2.Kind() == reflect.Struct {
forEachField(t2, fieldPath, do)
}
continue continue
} }
+13
View File
@@ -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)
}