Block.Filter can panic with no attrs

Make sure that we only dereference an attribute is it was set in the
filter. While not extremely useful, a provider could have a nested
object with no attributes.
pull/34472/head
James Bardin 2 years ago
parent 3a75362cce
commit 7ccb21d864

@ -50,10 +50,9 @@ func (b *Block) Filter(filterAttribute FilterT[*Attribute], filterBlock FilterT[
for name, attrS := range b.Attributes {
if filterAttribute == nil || !filterAttribute(name, attrS) {
ret.Attributes[name] = attrS
}
if attrS.NestedType != nil {
ret.Attributes[name].NestedType = filterNestedType(attrS.NestedType, filterAttribute)
if attrS.NestedType != nil {
ret.Attributes[name].NestedType = filterNestedType(attrS.NestedType, filterAttribute)
}
}
}

@ -175,6 +175,12 @@ func TestFilter(t *testing.T) {
Nesting: NestingList,
},
},
"missing_attributes": {
NestedType: &Object{
Nesting: NestingList,
},
Computed: true,
},
},
BlockTypes: map[string]*NestedBlock{

Loading…
Cancel
Save