Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/unable to decode negative zero int #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions decode_number_float_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion decode_number_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions decode_number_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down