Skip to content

fix: apply SliceFlagSeparator to env var sources#2309

Open
lawrence3699 wants to merge 1 commit intourfave:mainfrom
lawrence3699:fix/slice-separator-env-var
Open

fix: apply SliceFlagSeparator to env var sources#2309
lawrence3699 wants to merge 1 commit intourfave:mainfrom
lawrence3699:fix/slice-separator-env-var

Conversation

@lawrence3699
Copy link
Copy Markdown

What type of PR is this?

  • bug fix

What this PR does / why we need it:

SliceFlagSeparator is ignored when a flag's value comes from an environment variable. The custom separator only works for CLI arguments.

Root cause: setMultiValueParsingConfig is called during CLI argument parsing (via cmd.set), but PostParse—which handles env var sources—never applies the separator config to the flag's underlying SliceBase. The value is parsed with the default comma separator instead.

Fix: Call cmd.setMultiValueParsingConfig(flag) in the PostParse loop before env var values are read, so SliceBase has the correct separator config.

Before:

A="0 1" go run main.go   # SliceFlagSeparator=" " → returns ["0 1"] (single element)

After:

A="0 1" go run main.go   # SliceFlagSeparator=" " → returns ["0", "1"]

Which issue(s) this PR fixes:

Fixes #2262

Validation:

  • Added TestCommandSliceFlagSeparatorFromEnvVar — fails before the fix, passes after
  • All existing tests pass (go test ./..., go vet ./...)

SliceFlagSeparator was ignored when a flag's value came from an
environment variable. The separator config was only applied during
CLI argument parsing (via cmd.set), but PostParse—which handles
env var sources—never called setMultiValueParsingConfig.

Fixes urfave#2262
@lawrence3699 lawrence3699 requested a review from a team as a code owner April 12, 2026 05:23
Copilot AI review requested due to automatic review settings April 12, 2026 05:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a parsing bug where Command.SliceFlagSeparator was not honored when a slice flag’s value is sourced from environment variables (via PostParse), causing env-provided values to be split using the default separator instead of the configured one.

Changes:

  • Apply multi-value parsing configuration (SliceFlagSeparator, DisableSliceFlagSeparator, MapFlagKeyValueSeparator) before each flag’s PostParse() so env/file sources parse consistently with CLI parsing.
  • Add a regression test covering SliceFlagSeparator behavior when a StringSliceFlag is set via an env var source.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
command_run.go Ensures multi-value parsing config is applied prior to PostParse(), fixing env var parsing for slice/map flags.
command_test.go Adds a regression test validating that env-sourced StringSliceFlag respects SliceFlagSeparator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split separator in StringSliceFlag ignored when using environment variable as source

2 participants