mirror of
https://github.com/golang/go
synced 2024-11-20 04:34:41 -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:
parent
11fe7cd6e3
commit
53523f6a7d
@ -381,6 +381,7 @@ func (d *decodeState) array(v reflect.Value) {
|
|||||||
d.error(errPhase)
|
d.error(errPhase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i < av.Len() {
|
if i < av.Len() {
|
||||||
if !sv.IsValid() {
|
if !sv.IsValid() {
|
||||||
// Array. Zero the rest.
|
// Array. Zero the rest.
|
||||||
@ -392,6 +393,9 @@ func (d *decodeState) array(v reflect.Value) {
|
|||||||
sv.SetLen(i)
|
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.
|
// object consumes an object from d.data[d.off-1:], decoding into the value v.
|
||||||
|
Loading…
Reference in New Issue
Block a user