Skip to content

Commit 28f1efc

Browse files
authored
Decode: don't break on non-struct embed field (#810)
1 parent 7d69e4a commit 28f1efc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

unmarshaler.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,10 @@ func forEachField(t reflect.Type, path []int, do func(name string, path []int))
12111211
if t2.Kind() == reflect.Pointer {
12121212
t2 = t2.Elem()
12131213
}
1214-
forEachField(t2, fieldPath, do)
1214+
1215+
if t2.Kind() == reflect.Struct {
1216+
forEachField(t2, fieldPath, do)
1217+
}
12151218
continue
12161219
}
12171220

unmarshaler_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -3288,3 +3288,16 @@ func TestUnmarshal_RecursiveTableArray(t *testing.T) {
32883288
})
32893289
}
32903290
}
3291+
3292+
func TestUnmarshalEmbedNonString(t *testing.T) {
3293+
type Foo []byte
3294+
type doc struct {
3295+
Foo
3296+
}
3297+
3298+
d := doc{}
3299+
3300+
err := toml.Unmarshal([]byte(`foo = 'bar'`), &d)
3301+
require.NoError(t, err)
3302+
require.Nil(t, d.Foo)
3303+
}

0 commit comments

Comments
 (0)