hclsyntax: Fix another template loop panic
If individual template expressions in a loop have marks, merge those marks into the final result when joining.
This commit is contained in:
parent
d74545cb03
commit
f2f7dd7632
@ -153,6 +153,7 @@ func (e *TemplateJoinExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
|
|||||||
}
|
}
|
||||||
|
|
||||||
tuple, marks := tuple.Unmark()
|
tuple, marks := tuple.Unmark()
|
||||||
|
allMarks := []cty.ValueMarks{marks}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
it := tuple.ElementIterator()
|
it := tuple.ElementIterator()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
@ -193,10 +194,14 @@ func (e *TemplateJoinExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
|
|||||||
return cty.UnknownVal(cty.String).WithMarks(marks), diags
|
return cty.UnknownVal(cty.String).WithMarks(marks), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strVal, strValMarks := strVal.Unmark()
|
||||||
|
if len(strValMarks) > 0 {
|
||||||
|
allMarks = append(allMarks, strValMarks)
|
||||||
|
}
|
||||||
buf.WriteString(strVal.AsString())
|
buf.WriteString(strVal.AsString())
|
||||||
}
|
}
|
||||||
|
|
||||||
return cty.StringVal(buf.String()).WithMarks(marks), diags
|
return cty.StringVal(buf.String()).WithMarks(allMarks...), diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *TemplateJoinExpr) Range() hcl.Range {
|
func (e *TemplateJoinExpr) Range() hcl.Range {
|
||||||
|
@ -330,6 +330,34 @@ trim`,
|
|||||||
cty.StringVal("foobarbaz").Mark("sensitive"),
|
cty.StringVal("foobarbaz").Mark("sensitive"),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
|
{ // marks on individual elements propagate to the result
|
||||||
|
`%{ for s in secrets }${s}%{ endfor }`,
|
||||||
|
&hcl.EvalContext{
|
||||||
|
Variables: map[string]cty.Value{
|
||||||
|
"secrets": cty.ListVal([]cty.Value{
|
||||||
|
cty.StringVal("foo"),
|
||||||
|
cty.StringVal("bar").Mark("sensitive"),
|
||||||
|
cty.StringVal("baz"),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cty.StringVal("foobarbaz").Mark("sensitive"),
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{ // lots of marks!
|
||||||
|
`%{ for s in secrets }${s}%{ endfor }`,
|
||||||
|
&hcl.EvalContext{
|
||||||
|
Variables: map[string]cty.Value{
|
||||||
|
"secrets": cty.ListVal([]cty.Value{
|
||||||
|
cty.StringVal("foo").Mark("x"),
|
||||||
|
cty.StringVal("bar").Mark("y"),
|
||||||
|
cty.StringVal("baz").Mark("z"),
|
||||||
|
}).Mark("x"), // second instance of x
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cty.StringVal("foobarbaz").WithMarks(cty.NewValueMarks("x", "y", "z")),
|
||||||
|
0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user