Merge pull request #406 from hashicorp/alisdair/fix-panic-traversing-marked-map
Fix panic traversing marked map
This commit is contained in:
commit
a0de289809
@ -287,7 +287,7 @@ trim`,
|
||||
`hello%{ if false } ${target}%{ endif }`,
|
||||
&hcl.EvalContext{
|
||||
Variables: map[string]cty.Value{
|
||||
"target": cty.StringVal("world").WithMarks(cty.NewValueMarks("sensitive")),
|
||||
"target": cty.StringVal("world").Mark("sensitive"),
|
||||
},
|
||||
},
|
||||
cty.StringVal("hello"),
|
||||
@ -297,13 +297,25 @@ trim`,
|
||||
`${greeting} ${target}`,
|
||||
&hcl.EvalContext{
|
||||
Variables: map[string]cty.Value{
|
||||
"greeting": cty.StringVal("hello").WithMarks(cty.NewValueMarks("english")),
|
||||
"target": cty.StringVal("world").WithMarks(cty.NewValueMarks("sensitive")),
|
||||
"greeting": cty.StringVal("hello").Mark("english"),
|
||||
"target": cty.StringVal("world").Mark("sensitive"),
|
||||
},
|
||||
},
|
||||
cty.StringVal("hello world").WithMarks(cty.NewValueMarks("english", "sensitive")),
|
||||
0,
|
||||
},
|
||||
{ // can use marks by traversing complex values
|
||||
`Authenticate with "${secrets.passphrase}"`,
|
||||
&hcl.EvalContext{
|
||||
Variables: map[string]cty.Value{
|
||||
"secrets": cty.MapVal(map[string]cty.Value{
|
||||
"passphrase": cty.StringVal("my voice is my passport").Mark("sensitive"),
|
||||
}).Mark("sensitive"),
|
||||
},
|
||||
},
|
||||
cty.StringVal(`Authenticate with "my voice is my passport"`).WithMarks(cty.NewValueMarks("sensitive")),
|
||||
0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
7
ops.go
7
ops.go
@ -217,7 +217,12 @@ func GetAttr(obj cty.Value, attrName string, srcRange *Range) (cty.Value, Diagno
|
||||
}
|
||||
|
||||
idx := cty.StringVal(attrName)
|
||||
if obj.HasIndex(idx).False() {
|
||||
|
||||
// Here we drop marks from HasIndex result, in order to allow basic
|
||||
// traversal of a marked map in the same way we can traverse a marked
|
||||
// object
|
||||
hasIndex, _ := obj.HasIndex(idx).Unmark()
|
||||
if hasIndex.False() {
|
||||
return cty.DynamicVal, Diagnostics{
|
||||
{
|
||||
Severity: DiagError,
|
||||
|
@ -48,6 +48,15 @@ func TestApplyPath(t *testing.T) {
|
||||
cty.StringVal("hello"),
|
||||
``,
|
||||
},
|
||||
{
|
||||
cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("foo").Mark("x"),
|
||||
"b": cty.StringVal("bar").Mark("x"),
|
||||
}).Mark("x"),
|
||||
cty.GetAttrPath("a"),
|
||||
cty.StringVal("foo").Mark("x"),
|
||||
``,
|
||||
},
|
||||
{
|
||||
cty.ListValEmpty(cty.String),
|
||||
(cty.Path)(nil).Index(cty.NumberIntVal(0)),
|
||||
|
Loading…
Reference in New Issue
Block a user