We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
When parsing a document into a struct using pointers and omitempty, empty sections are interpreted as nil same as if they weren't defined at all.
omitempty
nil
The main issue with this behavior is that the action Marshal(Unmarshal(doc)) mutates the document.
Marshal(Unmarshal(doc))
To Reproduce
Run the following example:
package main import ( "fmt" "github.com/pelletier/go-toml/v2" ) type A struct { Nullable *struct { A string } `toml:"nullable,omitempty"` } type Doc struct { A *A `toml:"a,omitempty"` } func main() { doc1 := []byte(`[a] [a.nullable] `) doc2 := []byte(`[a]`) var d1 Doc if err := toml.Unmarshal(doc1, &d1); err != nil { panic(err) } fmt.Println(d1.A.Nullable) var d2 Doc if err := toml.Unmarshal(doc2, &d2); err != nil { panic(err) } fmt.Println(d2.A) }
which prints:
<nil> <nil>
Expected behavior
I'd expect it to return &Nullable{} in the first case as the section was defined.
&Nullable{}
Versions
Additional context
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Describe the bug
When parsing a document into a struct using pointers and
omitempty
, empty sections are interpreted asnil
same as if they weren't defined at all.The main issue with this behavior is that the action
Marshal(Unmarshal(doc))
mutates the document.To Reproduce
Run the following example:
which prints:
Expected behavior
I'd expect it to return
&Nullable{}
in the first case as the section was defined.Versions
Additional context
The text was updated successfully, but these errors were encountered: