Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2851d9f

Browse files
authored
fix: return empty array if no option multi-selected (#19224)
Related:#19145
1 parent91780db commit2851d9f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎cli/cliui/select.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ func RichMultiSelect(inv *serpent.Invocation, richOptions RichMultiSelectOptions
349349
}
350350

351351
// Check selected option, convert descriptions (line) to values
352-
varresults []string
352+
//
353+
// The function must return an initialized empty array, since it is later marshaled
354+
// into JSON. Otherwise, `var results []string` would be marshaled to "null".
355+
// See: https://github.com/golang/go/issues/27589
356+
results:= []string{}
353357
for_,sel:=rangeselected {
354358
custom:=true
355359
fori,option:=rangerichOptions.Options {

‎cli/cliui/select_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ func TestRichMultiSelect(t *testing.T) {
111111
allowCustom:true,
112112
want: []string{"aaa","bbb"},
113113
},
114+
{
115+
name:"NoOptionSelected",
116+
options: []codersdk.TemplateVersionParameterOption{
117+
{Name:"AAA",Description:"This is AAA",Value:"aaa"},
118+
{Name:"BBB",Description:"This is BBB",Value:"bbb"},
119+
{Name:"CCC",Description:"This is CCC",Value:"ccc"},
120+
},
121+
defaults: []string{},
122+
allowCustom:false,
123+
want: []string{},
124+
},
114125
}
115126

116127
for_,tt:=rangetests {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp