Skip to content

TrimSpace Config has no effect on StringSliceFlag #2169

@ayoisaiah

Description

@ayoisaiah

My urfave/cli version is

v3.3.8

Checklist

  • Are you running the latest v3 release? The list of releases is here.
  • Did you check the manual for your release? The v3 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Describe the bug

Strings arguments to a StringSliceFlag are always trimmed regardless of the TrimSpace configuration

To reproduce

// See flag_test.go

// Existing test
		{
			name:   "StringSliceFlag valid with TrimSpace",
			input:  "foo , bar ",
			output: []string{"foo", "bar"},
			fl:     &StringSliceFlag{Name: "names", Sources: EnvVars("NAMES"), Config: StringConfig{TrimSpace: true}},
		},

// Add a new test with TrimSpace set to false
		{
			name:   "StringSliceFlag valid without TrimSpace",
			input:  "foo , bar ",
			output: []string{"foo ", " bar "},
			fl:     &StringSliceFlag{Name: "names", Sources: EnvVars("NAMES"), Config: StringConfig{TrimSpace: false}},
		},

Observed behavior

Spaces are trimmed regardless:

[]string{"foo", "bar"}

Expected behavior

I expected it to preserve spaces with TrimSpace set to false

 []string{"foo ", " bar "}

Metadata

Metadata

Assignees

Labels

area/v3relates to / is being considered for v3kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into this

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions