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.
This commit is contained in:
James Bardin 2024-01-03 09:14:11 -05:00
parent 3a75362cce
commit 7ccb21d864
2 changed files with 9 additions and 4 deletions

View file

@ -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)
}
}
}

View file

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