diff options
| author | Rick Arnold <rickarnoldjr@gmail.com> | 2013-03-13 14:53:03 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-03-13 14:53:03 -0400 |
| commit | cb8aebf19d7291ec0acc7fcfc7d9fd0010f66cdc (patch) | |
| tree | 093736634a41ed76d983455c187b3ffc1596fba2 /src/pkg/encoding/json/decode.go | |
| parent | 06cbe78bd77789afb46b597466bcecf73c25d6d2 (diff) | |
| download | go-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.go')
| -rw-r--r-- | src/pkg/encoding/json/decode.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pkg/encoding/json/decode.go b/src/pkg/encoding/json/decode.go index d34e10f838..722037c309 100644 --- a/src/pkg/encoding/json/decode.go +++ b/src/pkg/encoding/json/decode.go @@ -261,6 +261,16 @@ func (d *decodeState) value(v reflect.Value) { } d.scan.step(&d.scan, '"') d.scan.step(&d.scan, '"') + + n := len(d.scan.parseState) + if n > 0 && d.scan.parseState[n-1] == parseObjectKey { + // d.scan thinks we just read an object key; finish the object + d.scan.step(&d.scan, ':') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '}') + } + return } |
