Skip to content

Commit

Permalink
Decode: don't break on non-struct embed field (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Aug 22, 2022
1 parent 7d69e4a commit 28f1efc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion unmarshaler.go
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions unmarshaler_test.go
Expand Up @@ -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)
}

0 comments on commit 28f1efc

Please sign in to comment.