diff --git a/gjson.go b/gjson.go index 148c88e..7bb82e9 100644 --- a/gjson.go +++ b/gjson.go @@ -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) { diff --git a/gjson_test.go b/gjson_test.go index 6f4dd7a..a1b939f 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -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",