1
0
mirror of https://github.com/golang/go synced 2024-11-20 00:44:45 -07:00

encoding/json: decode [] as empty slice, not nil slice

Test was already present, but bug in reflect.DeepEqual hid this bug.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5375090
This commit is contained in:
Russ Cox 2011-11-14 16:03:23 -05:00
parent 11fe7cd6e3
commit 53523f6a7d

View File

@ -381,6 +381,7 @@ func (d *decodeState) array(v reflect.Value) {
d.error(errPhase)
}
}
if i < av.Len() {
if !sv.IsValid() {
// Array. Zero the rest.
@ -392,6 +393,9 @@ func (d *decodeState) array(v reflect.Value) {
sv.SetLen(i)
}
}
if i == 0 && av.Kind() == reflect.Slice && sv.IsNil() {
sv.Set(reflect.MakeSlice(sv.Type(), 0, 0))
}
}
// object consumes an object from d.data[d.off-1:], decoding into the value v.