mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
#135 fix double negative
This commit is contained in:
parent
f6da8e62c3
commit
c966eaa031
@ -159,6 +159,14 @@ func (iter *Iterator) readFloat32SlowPath() (ret float32) {
|
|||||||
if iter.Error != nil && iter.Error != io.EOF {
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(str) == 0 {
|
||||||
|
iter.ReportError("readFloat32SlowPath", "empty number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if str[0] == '-' {
|
||||||
|
iter.ReportError("readFloat32SlowPath", "-- is not valid")
|
||||||
|
return
|
||||||
|
}
|
||||||
val, err := strconv.ParseFloat(str, 32)
|
val, err := strconv.ParseFloat(str, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
iter.Error = err
|
iter.Error = err
|
||||||
@ -233,6 +241,14 @@ func (iter *Iterator) readFloat64SlowPath() (ret float64) {
|
|||||||
if iter.Error != nil && iter.Error != io.EOF {
|
if iter.Error != nil && iter.Error != io.EOF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(str) == 0 {
|
||||||
|
iter.ReportError("readFloat64SlowPath", "empty number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if str[0] == '-' {
|
||||||
|
iter.ReportError("readFloat64SlowPath", "-- is not valid")
|
||||||
|
return
|
||||||
|
}
|
||||||
val, err := strconv.ParseFloat(str, 64)
|
val, err := strconv.ParseFloat(str, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
iter.Error = err
|
iter.Error = err
|
||||||
|
@ -3,6 +3,7 @@ package jsoniter
|
|||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
"testing"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_missing_object_end(t *testing.T) {
|
func Test_missing_object_end(t *testing.T) {
|
||||||
@ -65,3 +66,15 @@ func Test_invalid_array_input(t *testing.T) {
|
|||||||
obj := [0]string{}
|
obj := [0]string{}
|
||||||
should.NotNil(Unmarshal(input, &obj))
|
should.NotNil(Unmarshal(input, &obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_double_negative(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
var v interface{}
|
||||||
|
should.NotNil(json.Unmarshal([]byte(`--2`), &v))
|
||||||
|
var vFloat64 float64
|
||||||
|
should.NotNil(UnmarshalFromString(`--2`, &vFloat64))
|
||||||
|
var vFloat32 float32
|
||||||
|
should.NotNil(UnmarshalFromString(`--2`, &vFloat32))
|
||||||
|
var vInt int
|
||||||
|
should.NotNil(UnmarshalFromString(`--2`, &vInt))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user