config: make formatlist work on lists of length 1
removes treat-lists-as-scalar special casing for formatlist /cc @radeksimko fixes #2240
This commit is contained in:
parent
e88aeede9b
commit
c95f21cec1
|
@ -138,16 +138,6 @@ func interpolationFuncFormatList() ast.Function {
|
|||
|
||||
parts := StringList(s).Slice()
|
||||
|
||||
// 0 or 1 length lists are treated as scalars and repeated
|
||||
switch len(parts) {
|
||||
case 0:
|
||||
varargs[i-1] = ""
|
||||
continue
|
||||
case 1:
|
||||
varargs[i-1] = parts[0]
|
||||
continue
|
||||
}
|
||||
|
||||
// otherwise the list is sent down to be indexed
|
||||
varargs[i-1] = parts
|
||||
|
||||
|
|
|
@ -190,23 +190,18 @@ func TestInterpolateFuncFormatList(t *testing.T) {
|
|||
"A=1, B=2, C=3",
|
||||
false,
|
||||
},
|
||||
// formatlist of lists of length zero/one are repeated, just as scalars are
|
||||
{
|
||||
`${join(", ", formatlist("%s=%s", split(",", ""), split(",", "1,2,3")))}`,
|
||||
"=1, =2, =3",
|
||||
false,
|
||||
},
|
||||
{
|
||||
`${join(", ", formatlist("%s=%s", split(",", "A"), split(",", "1,2,3")))}`,
|
||||
"A=1, A=2, A=3",
|
||||
false,
|
||||
},
|
||||
// Mismatched list lengths generate an error
|
||||
{
|
||||
`${formatlist("%s=%2s", split(",", "A,B,C,D"), split(",", "1,2,3"))}`,
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
// Works with lists of length 1 [GH-2240]
|
||||
{
|
||||
`${formatlist("%s.id", split(",", "demo-rest-elb"))}`,
|
||||
NewStringList([]string{"demo-rest-elb.id"}).String(),
|
||||
false,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue