pelletier / go-toml

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

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

Closed marselester closed 11 months ago

marselester commented 1 year 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 1 year ago

Thank you for the bug report!

pelletier commented 11 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 11 months ago

Pushed go-toml v2.1.1 with this fix.

marselester commented 11 months ago

Awesome, thank you!