Skip to content

Commit b5e053c

Browse files
bug: expand interpreter args to multiple arguments
1 parent 3f647e7 commit b5e053c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

pkg/engine/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
211211
cmdArgs = append(cmdArgs, f.Name())
212212
}
213213

214+
// This is a bit hacky, but we want ARGS="x y" to expand to "x" and "y" not "x y" if used as arguments
215+
cmdArgs, err = shlex.Split(strings.Join(cmdArgs, " "))
216+
if err != nil {
217+
return nil, nil, err
218+
}
219+
214220
// This is a workaround for Windows, where the command interpreter is constructed with unix style paths
215221
// It converts unix style paths to windows style paths
216222
if runtime.GOOS == "windows" {

pkg/tests/runner_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,19 @@ func TestExport(t *testing.T) {
559559
require.NoError(t, err)
560560
assert.Equal(t, "TEST RESULT CALL: 3", x)
561561
}
562+
563+
func TestShlex(t *testing.T) {
564+
runner := tester.NewRunner(t)
565+
566+
runner.RespondWith(tester.Result{
567+
Func: types.CompletionFunctionCall{
568+
Name: "transient",
569+
},
570+
})
571+
x, err := runner.Run("", `{
572+
"args":" x y z "
573+
}`)
574+
require.NoError(t, err)
575+
// The fact the white space is all perfect means that the string didn't get passed as one arg but multiple
576+
assert.Equal(t, "x y z\n", x)
577+
}

pkg/tests/testdata/TestShlex/test.gpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
#!/usr/bin/env echo ${ARGS}

0 commit comments

Comments
 (0)