ソースを参照

fix: panic caused by empty string argument

Signed-off-by: Nick Sieger <[email protected]>
Nick Sieger 3 年 前
コミット
fd5e8b8c28
2 ファイル変更6 行追加1 行削除
  1. 1 1
      cmd/compatibility/convert.go
  2. 5 0
      cmd/compatibility/convert_test.go

+ 1 - 1
cmd/compatibility/convert.go

@@ -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++

+ 5 - 0
cmd/compatibility/convert_test.go

@@ -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) {