mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: roll back Unmarshal optimization + test
The second attempt at the Unmarshal optimization allowed panics to get out of the json package. Add test for that bug and remove the optimization. Let's stop trying to optimize Unmarshal. Fixes #4784. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7300108
This commit is contained in:
parent
da6207f7a4
commit
d340a89d9c
2 changed files with 29 additions and 19 deletions
|
|
@ -56,8 +56,7 @@ import (
|
|||
// an UnmarshalTypeError describing the earliest such error.
|
||||
//
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
|
||||
// Quick check for well-formedness.
|
||||
// Check for well-formedness.
|
||||
// Avoids filling out half a data structure
|
||||
// before discovering a JSON syntax error.
|
||||
var d decodeState
|
||||
|
|
@ -66,23 +65,6 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// skip heavy processing for primitive values
|
||||
var first byte
|
||||
var i int
|
||||
for i, first = range data {
|
||||
if first > ' ' || !isSpace(rune(first)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if first != '{' && first != '[' {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return &InvalidUnmarshalError{reflect.TypeOf(v)}
|
||||
}
|
||||
d.literalStore(data[i:], rv.Elem(), false)
|
||||
return d.savedError
|
||||
}
|
||||
|
||||
d.init(data)
|
||||
return d.unmarshal(v)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue