diff options
author | Joe Tsai <joetsai@digital-static.net> | 2017-12-05 22:53:48 -0800 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2018-02-14 21:34:26 +0000 |
commit | 91a6a2a30f95da8ae3fb6329a71c49ed13aa12ad (patch) | |
tree | 1924c3c82b14e38b9d9e22e2227d7661b8804a77 /src/encoding/json/decode_test.go | |
parent | 70a04f6880a2082a76f6282361b607f859db950f (diff) | |
download | go-git-91a6a2a30f95da8ae3fb6329a71c49ed13aa12ad.tar.gz |
encoding/json: make error capture logic in recover more type safe
Rather than only ignoring runtime.Error panics, which are a very
narrow set of possible panic values, switch it such that the json
package only captures panic values that have been properly wrapped
in a jsonError struct. This ensures that only intentional panics
originating from the json package are captured.
Fixes #23012
Change-Id: I5e85200259edd2abb1b0512ce6cc288849151a6d
Reviewed-on: https://go-review.googlesource.com/94019
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r-- | src/encoding/json/decode_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index 34b7ec6d97..90fdf93dbd 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -2166,3 +2166,17 @@ func TestUnmarshalEmbeddedPointerUnexported(t *testing.T) { } } } + +type unmarshalPanic struct{} + +func (unmarshalPanic) UnmarshalJSON([]byte) error { panic(0xdead) } + +func TestUnmarshalPanic(t *testing.T) { + defer func() { + if got := recover(); !reflect.DeepEqual(got, 0xdead) { + t.Errorf("panic() = (%T)(%v), want 0xdead", got, got) + } + }() + Unmarshal([]byte("{}"), &unmarshalPanic{}) + t.Fatalf("Unmarshal should have panicked") +} |