aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/json/decode_test.go
diff options
context:
space:
mode:
authorRick Arnold <rickarnoldjr@gmail.com>2013-03-13 14:53:03 -0400
committerRuss Cox <rsc@golang.org>2013-03-13 14:53:03 -0400
commitcb8aebf19d7291ec0acc7fcfc7d9fd0010f66cdc (patch)
tree093736634a41ed76d983455c187b3ffc1596fba2 /src/pkg/encoding/json/decode_test.go
parent06cbe78bd77789afb46b597466bcecf73c25d6d2 (diff)
downloadgo-cb8aebf19d7291ec0acc7fcfc7d9fd0010f66cdc.tar.xz
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
Diffstat (limited to 'src/pkg/encoding/json/decode_test.go')
-rw-r--r--src/pkg/encoding/json/decode_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pkg/encoding/json/decode_test.go b/src/pkg/encoding/json/decode_test.go
index e1bd918dda..037c5b2368 100644
--- a/src/pkg/encoding/json/decode_test.go
+++ b/src/pkg/encoding/json/decode_test.go
@@ -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)
+ }
+}