pelletier / go-toml

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

Stack overflow occurs when a struct embeds a non-exported struct #915

Closed marselester closed 6 months ago

marselester commented 7 months ago

Stack overflow occurs when a struct embeds a non-exported struct.

package main

import (
    toml "github.com/pelletier/go-toml/v2"
)

func main() {
    b := []byte(`
fizz = "..."
blah.a = "..."`)
    var cfg config
    if err := toml.Unmarshal(b, &cfg); err != nil {
        panic(err)
    }
}

type config struct {
    Fizz string `toml:"fizz"`
    blah `toml:"blah"`
}

type blah struct {
    A string `toml:"a"`
}

I would expect Unmarshal to return an error.

Versions

pelletier commented 7 months ago

Thank you for the bug report!

pelletier commented 6 months ago

This should have been fixed at the tip of the v2 branch. Feel free to re-open if anything doesn't work as expected!

pelletier commented 6 months ago

Pushed go-toml v2.1.1 with this fix.

marselester commented 6 months ago

Awesome, thank you!