Skip to content

Commit

Permalink
Fix negative without int part for valid
Browse files Browse the repository at this point in the history
fixes #210
  • Loading branch information
tidwall committed Mar 29, 2021
1 parent 15a2428 commit dee0375
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,12 @@ func validnumber(data []byte, i int) (outi int, ok bool) {
// sign
if data[i] == '-' {
i++
if i == len(data) {
return i, false
}
if data[i] < '0' || data[i] > '9' {
return i, false
}
}
// int
if i == len(data) {
Expand Down
3 changes: 3 additions & 0 deletions gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ func TestValidBasic(t *testing.T) {
testvalid(t, "00", false)
testvalid(t, "-00", false)
testvalid(t, "-.", false)
testvalid(t, "-.123", false)
testvalid(t, "0.0", true)
testvalid(t, "10.0", true)
testvalid(t, "10e1", true)
Expand Down Expand Up @@ -1094,6 +1095,8 @@ func TestValidBasic(t *testing.T) {
testvalid(t, `"a\\b\\\uFFA"`, false)
testvalid(t, string(complicatedJSON), true)
testvalid(t, string(exampleJSON), true)
testvalid(t, "[-]", false)
testvalid(t, "[-.123]", false)
}

var jsonchars = []string{"{", "[", ",", ":", "}", "]", "1", "0", "true",
Expand Down

0 comments on commit dee0375

Please sign in to comment.