• Andrey Mirtchovski's avatar
    encoding/json: properly unmarshal empty arrays. · e5793959
    Andrey Mirtchovski authored
    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
    e5793959
scanner_test.go 6.01 KB