mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: fix panics on type mismatches.
Fixes #4222. Fixes #4628. R=golang-dev, adg CC=golang-dev https://golang.org/cl/7100049
This commit is contained in:
parent
06af0ea3f3
commit
406ca3c2f1
2 changed files with 46 additions and 10 deletions
|
|
@ -1042,3 +1042,25 @@ func TestStringKind(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
var decodeTypeErrorTests = []struct {
|
||||
dest interface{}
|
||||
src string
|
||||
}{
|
||||
{new(string), `{"user": "name"}`}, // issue 4628.
|
||||
{new(error), `{}`}, // issue 4222
|
||||
{new(error), `[]`},
|
||||
{new(error), `""`},
|
||||
{new(error), `123`},
|
||||
{new(error), `true`},
|
||||
}
|
||||
|
||||
func TestUnmarshalTypeError(t *testing.T) {
|
||||
for _, item := range decodeTypeErrorTests {
|
||||
err := Unmarshal([]byte(item.src), item.dest)
|
||||
if _, ok := err.(*UnmarshalTypeError); !ok {
|
||||
t.Errorf("expected type error for Unmarshal(%q, type %T): got %v instead",
|
||||
item.src, item.dest, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue