mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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
1 changed files with 4 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue