diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-25 00:48:04 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-25 00:48:04 -0700 |
commit | e3c62b8de808c29ad70c1cfb98b4d1b164c05745 (patch) | |
tree | 0724da76664e893e7ecfad2d8ce4ea1b05918598 /compat/json | |
parent | a10285f9436f6e5372bcba1789348f1cc2794d9b (diff) | |
parent | d01fa91dcdfd428fb4b1c46b3961a1497c7a1102 (diff) |
Merge branch 'lukeshu/decode-type-errors'
Diffstat (limited to 'compat/json')
-rw-r--r-- | compat/json/compat_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go index df9d387..098ac85 100644 --- a/compat/json/compat_test.go +++ b/compat/json/compat_test.go @@ -181,6 +181,10 @@ func TestCompatUnmarshal(t *testing.T) { "two-objs": {In: `{} {}`, ExpOut: nil, ExpErr: `invalid character '{' after top-level value`}, "two-numbers1": {In: `00`, ExpOut: nil, ExpErr: `invalid character '0' after top-level value`}, "two-numbers2": {In: `1 2`, ExpOut: nil, ExpErr: `invalid character '2' after top-level value`}, + // 2e308 is slightly more than math.MaxFloat64 (~1.79e308) + "obj-overflow": {In: `{"foo":"bar", "baz":2e308, "qux": "orb"}`, ExpOut: map[string]any{"foo": "bar", "baz": nil, "qux": "orb"}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, + "ary-overflow": {In: `["foo",2e308,"bar",3e308]`, ExpOut: []any{"foo", nil, "bar", nil}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, + "existing-overflow": {In: `2e308`, InPtr: func() any { x := 4; return &x }(), ExpOut: 4, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type int`}, } for tcName, tc := range testcases { tc := tc @@ -219,6 +223,10 @@ func TestCompatDecode(t *testing.T) { "two-objs": {In: `{} {}`, ExpOut: map[string]any{}}, "two-numbers1": {In: `00`, ExpOut: float64(0)}, "two-numbers2": {In: `1 2`, ExpOut: float64(1)}, + // 2e308 is slightly more than math.MaxFloat64 (~1.79e308) + "obj-overflow": {In: `{"foo":"bar", "baz":2e308, "qux": "orb"}`, ExpOut: map[string]any{"foo": "bar", "baz": nil, "qux": "orb"}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, + "ary-overflow": {In: `["foo",2e308,"bar",3e308]`, ExpOut: []any{"foo", nil, "bar", nil}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, + "existing-overflow": {In: `2e308`, InPtr: func() any { x := 4; return &x }(), ExpOut: 4, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type int`}, } for tcName, tc := range testcases { tc := tc |