encoding/json: properly handle extra objects with fixed size arrays

If a fixed size array is passed in as the decode target and the JSON
to decode has extra array elements that are objects, then previously
the decoder would return a "data changing underfoot" error.

Fixes #3717.

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/7490046
This commit is contained in:
Rick Arnold 2013-03-13 14:53:03 -04:00 committed by Russ Cox
parent 06cbe78bd7
commit cb8aebf19d
2 changed files with 23 additions and 0 deletions

View file

@ -1178,3 +1178,16 @@ func TestUnmarshalJSONLiteralError(t *testing.T) {
t.Errorf("got err = %v; want out of range error", err)
}
}
// Test that extra object elements in an array do not result in a
// "data changing underfoot" error.
// Issue 3717
func TestSkipArrayObjects(t *testing.T) {
json := `[{}]`
var dest [0]interface{}
err := Unmarshal([]byte(json), &dest)
if err != nil {
t.Errorf("got error %q, want nil", err)
}
}