Skip to content

Add option to preserve empty values in ValueWithShadows #366

@matanw

Description

@matanw

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:

  1. Ignore – current default behavior, empty values are skipped.
  2. Preserve – empty values are kept in ValueWithShadows().
  3. 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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureCategorizes as related to a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions