Add option to preserve empty values in ValueWithShadows
Describe the feature
Currently, ValueWithShadows() ignores empty values after PR #316. This breaks workflows where an empty assignment is semantically meaningful (e.g., systemd unit files use empty values to reset previous assignments, see https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html: "If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect.").
Describe the solution you'd like
Introduce a new opt‑in option to preserve empty shadow values:
opts := ini.LoadOptions{
AllowShadows: true,
PreserveEmptyShadows: true, // new option
}
f, _ := ini.Load(data, opts)
vals := f.Section("Service").Key("Environment").ValueWithShadows()
// Expected: []string{"FOO=bar", ""}
Default behavior would remain unchanged to avoid breaking existing users.
Describe alternatives you've considered
Add a new field to LoadOptions, an enum named EmptyValueHandling, with three possible values:
- Ignore – current default behavior, empty values are skipped.
- Preserve – empty values are kept in ValueWithShadows().
- IgnorePrevious – when an empty value is encountered, all previous values for the key are discarded (systemd‑style reset).
Additional context
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Implementation offer: I’d be happy to open a PR implementing this feature if maintainers agree with the proposed design.