From 3773c915416a7787731903c9aa286776cad2b0cb Mon Sep 17 00:00:00 2001 From: Nick Chan <5746214+nickccm1122@users.noreply.github.com> Date: Mon, 23 Dec 2019 18:48:49 +0800 Subject: [PATCH 1/2] fix: unable to decode negative zero int --- decode_number_int.go | 2 +- decode_number_int_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/decode_number_int.go b/decode_number_int.go index 8429049..5326ff6 100644 --- a/decode_number_int.go +++ b/decode_number_int.go @@ -902,7 +902,7 @@ func (dec *Decoder) getInt64Negative() (int64, error) { // look for following numbers for ; dec.cursor < dec.length || dec.read(); dec.cursor++ { switch dec.data[dec.cursor] { - case '1', '2', '3', '4', '5', '6', '7', '8', '9': + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': return dec.getInt64() default: return 0, dec.raiseInvalidJSONErr(dec.cursor) diff --git a/decode_number_int_test.go b/decode_number_int_test.go index 909aef6..f8d8cfd 100644 --- a/decode_number_int_test.go +++ b/decode_number_int_test.go @@ -27,6 +27,11 @@ func TestDecoderInt(t *testing.T) { json: "1039405", expectedResult: 1039405, }, + { + name: "basic-negative-zero", + json: "-0", + expectedResult: 0, + }, { name: "basic-negative", json: "-2", From b2c358e5459111b1277245720a1fbeba32021756 Mon Sep 17 00:00:00 2001 From: Nick Chan <5746214+nickccm1122@users.noreply.github.com> Date: Mon, 23 Dec 2019 18:49:11 +0800 Subject: [PATCH 2/2] test: add test case for decode negative zero float --- decode_number_float_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/decode_number_float_test.go b/decode_number_float_test.go index 94deaff..f8eee83 100644 --- a/decode_number_float_test.go +++ b/decode_number_float_test.go @@ -169,6 +169,11 @@ func TestDecoderFloat64(t *testing.T) { json: "-8.2e-005", expectedResult: -0.000082, }, + { + name: "basic-float-negative-zero", + json: "-0.0", + expectedResult: 0.0, + }, { name: "basic-float", json: "2.4595",