lang/funcs: don't panic when transpose produces empty result
This commit is contained in:
parent
9ff83d8308
commit
6eaf1c23f9
|
@ -1179,7 +1179,6 @@ func sliceIndexes(args []cty.Value) (int, int, bool, error) {
|
||||||
return startIndex, endIndex, startKnown && endKnown, nil
|
return startIndex, endIndex, startKnown && endKnown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransposeFunc contructs a function that takes a map of lists of strings and
|
|
||||||
// TransposeFunc constructs a function that takes a map of lists of strings and
|
// TransposeFunc constructs a function that takes a map of lists of strings and
|
||||||
// swaps the keys and values to produce a new map of lists of strings.
|
// swaps the keys and values to produce a new map of lists of strings.
|
||||||
var TransposeFunc = function.New(&function.Spec{
|
var TransposeFunc = function.New(&function.Spec{
|
||||||
|
@ -1226,6 +1225,10 @@ var TransposeFunc = function.New(&function.Spec{
|
||||||
outputMap[outKey] = cty.ListVal(values)
|
outputMap[outKey] = cty.ListVal(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(outputMap) == 0 {
|
||||||
|
return cty.MapValEmpty(cty.List(cty.String)), nil
|
||||||
|
}
|
||||||
|
|
||||||
return cty.MapVal(outputMap), nil
|
return cty.MapVal(outputMap), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -2903,8 +2903,8 @@ func TestTranspose(t *testing.T) {
|
||||||
cty.MapVal(map[string]cty.Value{
|
cty.MapVal(map[string]cty.Value{
|
||||||
"key1": cty.ListValEmpty(cty.String),
|
"key1": cty.ListValEmpty(cty.String),
|
||||||
}),
|
}),
|
||||||
cty.NilVal,
|
cty.MapValEmpty(cty.List(cty.String)),
|
||||||
true,
|
false,
|
||||||
},
|
},
|
||||||
{ // bad map - value not a list
|
{ // bad map - value not a list
|
||||||
cty.MapVal(map[string]cty.Value{
|
cty.MapVal(map[string]cty.Value{
|
||||||
|
|
Loading…
Reference in New Issue