aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r--src/encoding/json/decode_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index d12495f90b..0b26b8eb91 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -1237,6 +1237,62 @@ var unmarshalTests = []struct {
out: (chan int)(nil),
err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeFor[chan int](), Offset: 1},
},
+
+ // #75619
+ {
+ CaseName: Name("QuotedInt/GoSyntax"),
+ in: `{"X": "-0000123"}`,
+ ptr: new(struct {
+ X int64 `json:",string"`
+ }),
+ out: struct {
+ X int64 `json:",string"`
+ }{-123},
+ },
+ {
+ CaseName: Name("QuotedInt/Invalid"),
+ in: `{"X": "123 "}`,
+ ptr: new(struct {
+ X int64 `json:",string"`
+ }),
+ err: &UnmarshalTypeError{Value: "number 123 ", Type: reflect.TypeFor[int64](), Field: "X", Offset: int64(len(`{"X": "123 "`))},
+ },
+ {
+ CaseName: Name("QuotedUint/GoSyntax"),
+ in: `{"X": "0000123"}`,
+ ptr: new(struct {
+ X uint64 `json:",string"`
+ }),
+ out: struct {
+ X uint64 `json:",string"`
+ }{123},
+ },
+ {
+ CaseName: Name("QuotedUint/Invalid"),
+ in: `{"X": "0x123"}`,
+ ptr: new(struct {
+ X uint64 `json:",string"`
+ }),
+ err: &UnmarshalTypeError{Value: "number 0x123", Type: reflect.TypeFor[uint64](), Field: "X", Offset: int64(len(`{"X": "0x123"`))},
+ },
+ {
+ CaseName: Name("QuotedFloat/GoSyntax"),
+ in: `{"X": "0x1_4p-2"}`,
+ ptr: new(struct {
+ X float64 `json:",string"`
+ }),
+ out: struct {
+ X float64 `json:",string"`
+ }{0x1_4p-2},
+ },
+ {
+ CaseName: Name("QuotedFloat/Invalid"),
+ in: `{"X": "1.5e1_"}`,
+ ptr: new(struct {
+ X float64 `json:",string"`
+ }),
+ err: &UnmarshalTypeError{Value: "number 1.5e1_", Type: reflect.TypeFor[float64](), Field: "X", Offset: int64(len(`{"X": "1.5e1_"`))},
+ },
}
func TestMarshal(t *testing.T) {