Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: urfave/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.23.8
Choose a base ref
...
head repository: urfave/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.23.9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 16, 2023

  1. Fixes #1648

    Remove trim of whitespace in `StringSliceFlag` values, matching the
    behavior of `StringFlag`.
    palsivertsen committed Jan 16, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    kzaher Krunoslav Zaher
    Copy the full SHA
    6bb383c View commit details

Commits on Jan 17, 2023

  1. Copy the full SHA
    fc28a1c View commit details
Showing with 40 additions and 1 deletion.
  1. +1 −1 flag_string_slice.go
  2. +39 −0 flag_test.go
2 changes: 1 addition & 1 deletion flag_string_slice.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func (s *StringSlice) Set(value string) error {
}

for _, t := range flagSplitMultiValues(value) {
s.slice = append(s.slice, strings.TrimSpace(t))
s.slice = append(s.slice, t)
}

return nil
39 changes: 39 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
@@ -758,6 +758,45 @@ func TestStringSliceFlagValueFromContext(t *testing.T) {
expect(t, f.Get(ctx), []string{"a", "b", "c"})
}

func TestStringSliceFlag_MatchStringFlagBehavior(t *testing.T) {
t.Parallel()

values := []string{
"asd",
"123",
" asd ", // leading and tailing space
}
for testNum, value := range values {
value := value
t.Run(fmt.Sprintf("%d", testNum), func(t *testing.T) {
t.Parallel()

app := App{
Flags: []Flag{
&StringFlag{Name: "string"},
&StringSliceFlag{Name: "slice"},
},
Action: func(ctx *Context) error {
f1, f2 := ctx.String("string"), ctx.StringSlice("slice")
if l := len(f2); l != 1 {
t.Fatalf("StringSliceFlag should result in exactly one value, got %d", l)
}

v1, v2 := f1, f2[0]
if v1 != v2 {
t.Errorf("Expected StringSliceFlag to parse the same value as StringFlag (%q), got %q", v1, v2)
}
return nil
},
}

if err := app.Run([]string{"", "--string", value, "--slice", value}); err != nil {
t.Errorf("app run error: %s", err)
}
})
}
}

var intFlagTests = []struct {
name string
expected string