Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/v1.11/BUG FIXES-20250303-125722.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'lang/funcs/transpose: Avoid crash due to map with null values'
time: 2025-03-03T12:57:22.400359Z
custom:
Issue: "36611"
6 changes: 6 additions & 0 deletions internal/lang/funcs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,14 @@ var TransposeFunc = function.New(&function.Spec{

for it := inputMap.ElementIterator(); it.Next(); {
inKey, inVal := it.Element()
if inVal.IsNull() {
return cty.MapValEmpty(cty.List(cty.String)), errors.New("input must not contain null list")
}
for iter := inVal.ElementIterator(); iter.Next(); {
_, val := iter.Element()
if val.IsNull() {
return cty.MapValEmpty(cty.List(cty.String)), errors.New("input list must not contain null string")
}
if !val.Type().Equals(cty.String) {
return cty.MapValEmpty(cty.List(cty.String)), errors.New("input must be a map of lists of strings")
}
Expand Down
31 changes: 31 additions & 0 deletions internal/lang/funcs/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,37 @@ func TestTranspose(t *testing.T) {
}).WithMarks(cty.NewValueMarks("beep", "boop", "bloop")),
false,
},
{
cty.NullVal(cty.Map(cty.List(cty.String))),
cty.NilVal,
true,
},
{
cty.MapVal(map[string]cty.Value{
"test": cty.NullVal(cty.List(cty.String)),
}),
cty.NilVal,
true,
},
{
cty.MapVal(map[string]cty.Value{
"test": cty.ListVal([]cty.Value{cty.NullVal(cty.String)}),
}),
cty.NilVal,
true,
},
{
cty.UnknownVal(cty.Map(cty.List(cty.String))),
cty.UnknownVal(cty.Map(cty.List(cty.String))).RefineNotNull(),
false,
},
{
cty.MapVal(map[string]cty.Value{
"test": cty.ListVal([]cty.Value{cty.UnknownVal(cty.String)}),
}),
cty.UnknownVal(cty.Map(cty.List(cty.String))).RefineNotNull(),
false,
},
}

for _, test := range tests {
Expand Down