Merge pull request #20891 from hashicorp/b-helper-schema-setSet-panic
helper/schema: Prevent setSet() panic with typed nil
This commit is contained in:
commit
d5a8545a15
|
@ -341,6 +341,11 @@ func (w *MapFieldWriter) setSet(
|
|||
// problems when the old data isn't wiped first.
|
||||
w.clearTree(addr)
|
||||
|
||||
if value.(*Set) == nil {
|
||||
w.result[k+".#"] = "0"
|
||||
return nil
|
||||
}
|
||||
|
||||
for code, elem := range value.(*Set).m {
|
||||
if err := w.set(append(addrCopy, code), elem); err != nil {
|
||||
return err
|
||||
|
|
|
@ -203,6 +203,15 @@ func TestMapFieldWriter(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
"set typed nil": {
|
||||
[]string{"set"},
|
||||
func() *Set { return nil }(),
|
||||
false,
|
||||
map[string]string{
|
||||
"set.#": "0",
|
||||
},
|
||||
},
|
||||
|
||||
"set resource": {
|
||||
[]string{"setDeep"},
|
||||
[]interface{}{
|
||||
|
|
Loading…
Reference in New Issue