Fix negative without int part for valid

fixes #210
This commit is contained in:
tidwall 2021-03-28 18:30:25 -07:00
parent 15a2428bae
commit dee0375ffd
2 changed files with 9 additions and 0 deletions

View File

@ -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) {

View File

@ -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)
@ -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",