Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6520)

Issue 7196050: code review 7196050: encoding/json: properly unmarshal empty arrays.

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 3 months ago by aam
Modified:
10 years, 9 months ago
Reviewers:
adg, rsc
CC:
adg, dave_cheney.net, rsc, golang-dev
Visibility:
Public.

Description

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.

Patch Set 1 #

Patch Set 2 : diff -r d123462e7f18 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r d123462e7f18 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r d123462e7f18 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r d123462e7f18 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+7 lines, -4 lines) Patch
M src/pkg/encoding/json/decode.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/encoding/json/decode_test.go View 1 2 3 4 1 chunk +6 lines, -0 lines 0 comments Download
M src/pkg/encoding/json/scanner_test.go View 1 1 chunk +0 lines, -3 lines 0 comments Download

Messages

Total messages: 10
aam
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 3 months ago (2013-01-24 19:33:32 UTC) #1
adg
What happens if you unmarshal null into an []interface{} value? Can you add a test ...
11 years, 3 months ago (2013-01-24 23:23:18 UTC) #2
aam
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 3 months ago (2013-01-24 23:41:24 UTC) #3
adg
LGTM But I'd like a second opinion.
11 years, 3 months ago (2013-01-24 23:45:54 UTC) #4
dave_cheney.net
On 2013/01/24 23:45:54, adg wrote: > LGTM > > But I'd like a second opinion. ...
11 years, 3 months ago (2013-01-25 00:09:22 UTC) #5
aam
Hello adg@golang.org, dave@cheney.net (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 3 months ago (2013-01-25 00:13:10 UTC) #6
aam
the issue appeared on IRC. in its shortest form it's a difference between an original ...
11 years, 3 months ago (2013-01-25 00:15:39 UTC) #7
rsc
LGTM Sure.
11 years, 3 months ago (2013-01-30 17:06:43 UTC) #8
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=49d533bb7cd3 *** encoding/json: properly unmarshal empty arrays. The JSON unmarshaller failed to ...
11 years, 3 months ago (2013-01-30 17:10:35 UTC) #9
remyoudompheng
10 years, 9 months ago (2013-07-20 21:24:49 UTC) #10
R=close
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b