mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: don't panic on incorrect map argument
Fixes #8305. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/145680044
This commit is contained in:
parent
94f3d8cfed
commit
7e8218aedd
2 changed files with 15 additions and 3 deletions
|
|
@ -445,7 +445,7 @@ func (d *decodeState) array(v reflect.Value) {
|
|||
}
|
||||
|
||||
// object consumes an object from d.data[d.off-1:], decoding into the value v.
|
||||
// the first byte of the object ('{') has been read already.
|
||||
// the first byte ('{') of the object has been read already.
|
||||
func (d *decodeState) object(v reflect.Value) {
|
||||
// Check for unmarshaler.
|
||||
u, ut, pv := d.indirect(v, false)
|
||||
|
|
@ -478,7 +478,9 @@ func (d *decodeState) object(v reflect.Value) {
|
|||
t := v.Type()
|
||||
if t.Key().Kind() != reflect.String {
|
||||
d.saveError(&UnmarshalTypeError{"object", v.Type()})
|
||||
break
|
||||
d.off--
|
||||
d.next() // skip over { } in input
|
||||
return
|
||||
}
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.MakeMap(t))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue