diff --git a/main.go b/main.go index f0c736acc..6ab370753 100644 --- a/main.go +++ b/main.go @@ -153,7 +153,7 @@ func wrappedMain() int { // after the first non-flag arg. idx := -1 for i, v := range args { - if v[0] != '-' { + if len(v) > 0 && v[0] != '-' { idx = i break } diff --git a/main_test.go b/main_test.go index 4c6cd5816..154d27bf5 100644 --- a/main_test.go +++ b/main_test.go @@ -56,6 +56,22 @@ func TestMain_cliArgsFromEnv(t *testing.T) { false, }, + { + "cli string has blank values", + []string{testCommandName, "bar", "", "baz"}, + "-foo bar", + []string{"-foo", "bar", "bar", "", "baz"}, + false, + }, + + { + "cli string has blank values before the command", + []string{"", testCommandName, "bar"}, + "-foo bar", + []string{"-foo", "bar", "bar"}, + false, + }, + { // this should fail gracefully, this is just testing // that we don't panic with our slice arithmetic