Unmark values before testing for truth in conditionals

In conditional expressions that involve a marked value,
Unmark the value before inspecting its truthiness,
to avoid a mark panic in cty
This commit is contained in:
Pam Selle 2020-12-03 10:51:18 -05:00
parent cef803d9d2
commit 3b45fd43af
2 changed files with 14 additions and 0 deletions

View File

@ -624,6 +624,8 @@ func (e *ConditionalExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostic
return cty.UnknownVal(resultType), diags
}
// Unmark result before testing for truthiness
condResult, _ = condResult.UnmarkDeep()
if condResult.True() {
diags = append(diags, trueDiags...)
if convs[0] != nil {

View File

@ -1582,6 +1582,18 @@ EOT
cty.DynamicVal,
0,
},
{ // marked conditional
`var.foo ? 1 : 0`,
&hcl.EvalContext{
Variables: map[string]cty.Value{
"var": cty.ObjectVal(map[string]cty.Value{
"foo": cty.BoolVal(true),
}).Mark("sensitive"),
},
},
cty.NumberIntVal(1),
0,
},
}
for _, test := range tests {