-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
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
Questionable behavior of 'omitempty' tag #786
Comments
Not sure if it's worth creating a new issue, so I'll ask here. I can't set alignment for toml lists in the encoder. |
Thanks for the bug report!
You're right, those extra new lines shouldn't be emitted.
I am not sure I understand the problem. Can you share an example?
Do you have some code to reproduce the issue? |
Yes, see the first # given
[[custom]]
# names for generator, braces are expanded like in shell
name = 'omit'
# expected
[[custom]]
# names for generator, braces are expanded like in shell
name = 'omit'
# randomize starting time with [0,step)
randomize = false
yes, if I use [[custom]]
# names for generator, braces are expanded like in shell
name = 'omit'
# randomize starting time with [0,step)
randomize = false |
Hi, also having this issue. It looks like go-toml is creating new lines when omit empty is defined, instead of discarding the lines. Also, I expect objects like in the example below to be omitted when all the keys in the object are omitted. type Dependencies struct {
Dependencies []string `toml:"dependencies,multiline,omitempty"`
BuildDependencies []string `toml:"buildDependencies,multiline,omitempty"`
OptionalDependencies []string `toml:"optionalDependencies,multiline,omitempty"`
}
type Test struct {
Dependencies Dependencies `toml:"dependencies,omitempty"
} Result: (notice empty lines) [dependencies]
Expected result would be an empty file. |
@Felixoid for the indentation issue, you also need to I started working on those extra newlines and omitempty issues. It's going to take a bit because most tests were using |
@Felixoid @stingalleman Pull requests #803 and #798 have been merged. Unless I missed something those two should fix both the extra new lines and the incorrect propagation of omitempty. Let me know if it works! |
Hello, I didn't come right after the fix. I've had a corona, and then just everything went south The output now is correct in regard to the Should I create a separate issue, or could we discuss it here? |
Describe the bug
Hello. I see the current behavior of
omitempty
flag as a bit confusing because of a few factors:To Reproduce
it produces (includes empty line on the end)
Expected behavior
I expect another result:
Versions
github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU=
Additional context
Add any other context about the problem here that you think may help to diagnose.
The text was updated successfully, but these errors were encountered: