Skip to content

Commit

Permalink
fix empty array cornercase
Browse files Browse the repository at this point in the history
allows empty param if explicit with forced quotes
  • Loading branch information
davidovich committed May 20, 2022
1 parent e94c561 commit 97532ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 9 additions & 6 deletions pkg/summon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,20 @@ func (d *Driver) RenderArgs(args ...string) ([]string, error) {
continue
}

inner := rt
var renderedTargets = []string{rt}
if strings.HasPrefix(rt, "[") && strings.HasSuffix(rt, "]") {
inner = strings.Trim(rt, "[]")
inner := strings.Trim(rt, "[]")

if inner == "" {
renderedTargets = []string{""}
continue
} else {
renderedTargets, err = shlex.Split(inner, true)
if err != nil {
return nil, err
if inner == `""` {
renderedTargets = []string{""}
} else {
renderedTargets, err = shlex.Split(inner, true)
if err != nil {
return nil, err
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/summon/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ func TestFlattenStrings(t *testing.T) {
args: []interface{}{},
want: []string{},
},
{
name: "empty-slice",
args: []interface{}{[]interface{}{}},
want: []string{},
},
{
name: "slice-of-slice-of-string",
args: []interface{}{[]string{"elem"}},
Expand Down Expand Up @@ -620,8 +625,8 @@ func TestFlagUsages(t *testing.T) {
expected: []string{"arg"},
},
{
name: "empty-array-used-to-insert-empty-arg-pos",
args: []string{`[{{flagValue "inexistant"}}]`, "arg"},
name: "empty-array-with-quotes-used-to-insert-empty-arg-pos",
args: []string{`["{{flagValue "inexistant"}}"]`, "arg"},
expected: []string{"", "arg"},
},
}
Expand Down

0 comments on commit 97532ce

Please sign in to comment.