pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.69k stars 206 forks source link

panic unmarshaling array of tables #839

Open jmank88 opened 1 year ago

jmank88 commented 1 year ago

Describe the bug Unmarshaling to a field of a table in an array of tables causes a panic.

To Reproduce https://go.dev/play/p/l2KDjY4lX-3

m := struct {
    A []struct {
        B struct{}
    }
}{}
fmt.Println(toml.Unmarshal([]byte(`[[A.B]]`), &m))

Expected behavior If this is invalid, I expect an error rather than a panic.

Versions

pelletier commented 1 year ago

Thank you for the bug report! I'll take a look when I have time, but feel free to send a pull request in the meantime!

jmank88 commented 1 year ago

@pelletier I started a draft that highlights the problematic area (#840). Is returning an error the correct thing to do here?

pelletier commented 1 year ago

You're correct: this should be an error, because the array of tables is on A.B, and B is a struct, not a slice.