Merge pull request #19587 from hashicorp/jbardin/safe-appends

don't modify argument slices
This commit is contained in:
James Bardin 2018-12-10 15:10:02 -05:00 committed by GitHub
commit 8ab5698e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -174,6 +174,9 @@ func (r *DiffFieldReader) readPrimitive(
func (r *DiffFieldReader) readSet(
address []string, schema *Schema) (FieldReadResult, error) {
// copy address to ensure we don't modify the argument
address = append([]string(nil), address...)
prefix := strings.Join(address, ".") + "."
// Create the set that will be our result

View File

@ -98,6 +98,9 @@ func (r *MapFieldReader) readPrimitive(
func (r *MapFieldReader) readSet(
address []string, schema *Schema) (FieldReadResult, error) {
// copy address to ensure we don't modify the argument
address = append([]string(nil), address...)
// Get the number of elements in the list
countRaw, err := r.readPrimitive(
append(address, "#"), &Schema{Type: TypeInt})