mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-09 07:05:33 -06:00
Allow null values in Compact function
The function would previously panic when one or more null values were among the arguments. The new behavior treats nulls as empty strings, therefore, it removes them.
This commit is contained in:
parent
5ac920223f
commit
983af7a183
@ -246,7 +246,7 @@ var CompactFunc = function.New(&function.Spec{
|
||||
|
||||
for it := listVal.ElementIterator(); it.Next(); {
|
||||
_, v := it.Element()
|
||||
if v.AsString() == "" {
|
||||
if v.IsNull() || v.AsString() == "" {
|
||||
continue
|
||||
}
|
||||
outputList = append(outputList, v)
|
||||
|
@ -572,6 +572,7 @@ func TestCompact(t *testing.T) {
|
||||
cty.StringVal("test"),
|
||||
cty.StringVal(""),
|
||||
cty.StringVal("test"),
|
||||
cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.StringVal("test"),
|
||||
@ -588,6 +589,14 @@ func TestCompact(t *testing.T) {
|
||||
cty.ListValEmpty(cty.String),
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.NullVal(cty.String),
|
||||
cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.ListValEmpty(cty.String),
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.ListValEmpty(cty.String),
|
||||
cty.ListValEmpty(cty.String),
|
||||
@ -610,6 +619,7 @@ func TestCompact(t *testing.T) {
|
||||
cty.StringVal("test"),
|
||||
cty.UnknownVal(cty.String),
|
||||
cty.StringVal(""),
|
||||
cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.UnknownVal(cty.List(cty.String)),
|
||||
false,
|
||||
|
Loading…
Reference in New Issue
Block a user