fix: panic caused by empty string argument

Signed-off-by: Nick Sieger <nick@nicksieger.com>
This commit is contained in:
Nick Sieger 2022-06-28 10:18:38 -05:00
parent dbf52d3f45
commit fd5e8b8c28
No known key found for this signature in database
GPG Key ID: 222EA328BD6E402A
2 changed files with 6 additions and 1 deletions

View File

@ -50,7 +50,7 @@ func Convert(args []string) []string {
l := len(args)
for i := 0; i < l; i++ {
arg := args[i]
if arg[0] != '-' {
if len(arg) > 0 && arg[0] != '-' {
// not a top-level flag anymore, keep the rest of the command unmodified
if arg == compose.PluginName {
i++

View File

@ -68,6 +68,11 @@ func Test_convert(t *testing.T) {
args: []string{"--log-level", "INFO", "up"},
want: []string{"--log-level", "INFO", "compose", "up"},
},
{
name: "empty string argument",
args: []string{"--project-directory", "", "ps"},
want: []string{"compose", "--project-directory", "", "ps"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {