From e38edfa53173c054ff97a5c51f90df0da60f16f5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 Feb 2023 18:55:57 -0700 Subject: jsonparse: Reword error messages to match encoding/json --- compat/json/compat_test.go | 18 ++++++++++++++++++ compat/json/testdata/fuzz/FuzzEquiv/1071d2f6e5b5f7d3 | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/6bced2300496f15c | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/6daf246742074967 | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/7c3168c77fc059cb | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/a955c588d78b5c3a | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/cf667c6f1f3282c1 | 2 ++ compat/json/testdata/fuzz/FuzzEquiv/ef2c8755a89034da | 2 ++ 8 files changed, 32 insertions(+) create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/1071d2f6e5b5f7d3 create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/6bced2300496f15c create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/6daf246742074967 create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/7c3168c77fc059cb create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/a955c588d78b5c3a create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/cf667c6f1f3282c1 create mode 100644 compat/json/testdata/fuzz/FuzzEquiv/ef2c8755a89034da (limited to 'compat/json') diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go index 6aab103..cf9e359 100644 --- a/compat/json/compat_test.go +++ b/compat/json/compat_test.go @@ -188,6 +188,24 @@ func TestCompatUnmarshal(t *testing.T) { "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`}, + // syntax error messages + "syntax-01": {In: `{}x`, ExpErr: `invalid character 'x' after top-level value`}, + "syntax-02": {In: `x`, ExpErr: `invalid character 'x' looking for beginning of value`}, + "syntax-03": {In: `{x`, ExpErr: `invalid character 'x' looking for beginning of object key string`}, + "syntax-04": {In: `{""x`, ExpErr: `invalid character 'x' after object key`}, + "syntax-05": {In: `{"":0x`, ExpErr: `invalid character 'x' after object key:value pair`}, + "syntax-06": {In: `[0x`, ExpErr: `invalid character 'x' after array element`}, + "syntax-07": {In: "\"\x01\"", ExpErr: `invalid character '\x01' in string literal`}, + "syntax-08": {In: `"\x`, ExpErr: `invalid character 'x' in string escape code`}, + "syntax-09": {In: `"\ux`, ExpErr: `invalid character 'x' in \u hexadecimal character escape`}, + "syntax-10": {In: `"\u0x`, ExpErr: `invalid character 'x' in \u hexadecimal character escape`}, + "syntax-11": {In: `"\u00x`, ExpErr: `invalid character 'x' in \u hexadecimal character escape`}, + "syntax-12": {In: `"\u000x`, ExpErr: `invalid character 'x' in \u hexadecimal character escape`}, + "syntax-13": {In: `-x`, ExpErr: `invalid character 'x' in numeric literal`}, + "syntax-14": {In: `0.x`, ExpErr: `invalid character 'x' after decimal point in numeric literal`}, + "syntax-15": {In: `1ex`, ExpErr: `invalid character 'x' in exponent of numeric literal`}, + "syntax-16": {In: `1e+x`, ExpErr: `invalid character 'x' in exponent of numeric literal`}, + "syntax-17": {In: `fx`, ExpErr: `invalid character 'x' in literal false (expecting 'a')`}, } for tcName, tc := range testcases { tc := tc diff --git a/compat/json/testdata/fuzz/FuzzEquiv/1071d2f6e5b5f7d3 b/compat/json/testdata/fuzz/FuzzEquiv/1071d2f6e5b5f7d3 new file mode 100644 index 0000000..1095817 --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/1071d2f6e5b5f7d3 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("0EA") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/6bced2300496f15c b/compat/json/testdata/fuzz/FuzzEquiv/6bced2300496f15c new file mode 100644 index 0000000..4bc9c61 --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/6bced2300496f15c @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{0") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/6daf246742074967 b/compat/json/testdata/fuzz/FuzzEquiv/6daf246742074967 new file mode 100644 index 0000000..b1c3453 --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/6daf246742074967 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("\"\\uX") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/7c3168c77fc059cb b/compat/json/testdata/fuzz/FuzzEquiv/7c3168c77fc059cb new file mode 100644 index 0000000..b95f079 --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/7c3168c77fc059cb @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("\"\x1e") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/a955c588d78b5c3a b/compat/json/testdata/fuzz/FuzzEquiv/a955c588d78b5c3a new file mode 100644 index 0000000..b135daa --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/a955c588d78b5c3a @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("0.A") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/cf667c6f1f3282c1 b/compat/json/testdata/fuzz/FuzzEquiv/cf667c6f1f3282c1 new file mode 100644 index 0000000..f6ab571 --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/cf667c6f1f3282c1 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("\"\\0") diff --git a/compat/json/testdata/fuzz/FuzzEquiv/ef2c8755a89034da b/compat/json/testdata/fuzz/FuzzEquiv/ef2c8755a89034da new file mode 100644 index 0000000..7d9478d --- /dev/null +++ b/compat/json/testdata/fuzz/FuzzEquiv/ef2c8755a89034da @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("0E+A") -- cgit v1.2.3-2-g168b