Commit 53523f6a authored by Russ Cox's avatar Russ Cox

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
parent 11fe7cd6
...@@ -381,6 +381,7 @@ func (d *decodeState) array(v reflect.Value) { ...@@ -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) { ...@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment