]> Cypherpunks repositories - gostls13.git/commit
encoding/json: properly unmarshal empty arrays.
authorAndrey Mirtchovski <mirtchovski@gmail.com>
Wed, 30 Jan 2013 17:10:32 +0000 (09:10 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 30 Jan 2013 17:10:32 +0000 (09:10 -0800)
commite57939590518b3af48dcddee0394339ef9ede1cc
treea3acbc6859d2ee2180c244f7c5bf6177e511e613
parente6861d8c34002b7f1b8a12b03672fda02f02d7ed
encoding/json: properly unmarshal empty arrays.

The JSON unmarshaller failed to allocate an array when there
are no values for the input causing the `[]` unmarshalled
to []interface{} to generate []interface{}(nil) rather than
[]interface{}{}. This wasn't caught in the tests because Decode()
works correctly and because jsonBig never generated zero-sized
arrays. The modification to scanner_test.go quickly triggers
the error:

without the change to decoder.go, but with the change to scanner_test.go:

$ go test
--- FAIL: TestUnmarshalMarshal (0.10 seconds)
decode_test.go:446: Marshal jsonBig
scanner_test.go:206: diverge at 70: «03c1OL6$":null},{"[=» vs «03c1OL6$":[]},{"[=^\»
FAIL
exit status 1
FAIL encoding/json 0.266s

Also added a simple regression to decode_test.go.

R=adg, dave, rsc
CC=golang-dev
https://golang.org/cl/7196050
src/pkg/encoding/json/decode.go
src/pkg/encoding/json/decode_test.go
src/pkg/encoding/json/scanner_test.go