mirror of
https://github.com/json-iterator/go.git
synced 2024-11-27 08:30:57 +02:00
Fix exponent parsing
This commit is contained in:
parent
d336ee6da6
commit
0d6dae80e1
@ -136,7 +136,7 @@ func (any *stringAny) ToFloat64() float64 {
|
||||
// eg 123true => 123, -12.12xxa => -12.12
|
||||
endPos := 1
|
||||
for i := 1; i < len(any.val); i++ {
|
||||
if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' {
|
||||
if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' {
|
||||
endPos = i + 1
|
||||
continue
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ load_loop:
|
||||
for i := iter.head; i < iter.tail; i++ {
|
||||
c := iter.buf[i]
|
||||
switch c {
|
||||
case '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
case '+', '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
str = append(str, c)
|
||||
continue
|
||||
default:
|
||||
|
@ -14,6 +14,34 @@ var floatConvertMap = map[string]float64{
|
||||
`"true"`: 0,
|
||||
`"false"`: 0,
|
||||
|
||||
"1e1": 10,
|
||||
"1e+1": 10,
|
||||
"1e-1": .1,
|
||||
"1E1": 10,
|
||||
"1E+1": 10,
|
||||
"1E-1": .1,
|
||||
|
||||
"-1e1": -10,
|
||||
"-1e+1": -10,
|
||||
"-1e-1": -.1,
|
||||
"-1E1": -10,
|
||||
"-1E+1": -10,
|
||||
"-1E-1": -.1,
|
||||
|
||||
`"1e1"`: 10,
|
||||
`"1e+1"`: 10,
|
||||
`"1e-1"`: .1,
|
||||
`"1E1"`: 10,
|
||||
`"1E+1"`: 10,
|
||||
`"1E-1"`: .1,
|
||||
|
||||
`"-1e1"`: -10,
|
||||
`"-1e+1"`: -10,
|
||||
`"-1e-1"`: -.1,
|
||||
`"-1E1"`: -10,
|
||||
`"-1E+1"`: -10,
|
||||
`"-1E-1"`: -.1,
|
||||
|
||||
"123": 123,
|
||||
`"123true"`: 123,
|
||||
`"+"`: 0,
|
||||
|
@ -29,7 +29,10 @@ func Test_read_big_int(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_read_float(t *testing.T) {
|
||||
inputs := []string{`1.1`, `1000`, `9223372036854775807`, `12.3`, `-12.3`, `720368.54775807`, `720368.547758075`}
|
||||
inputs := []string{
|
||||
`1.1`, `1000`, `9223372036854775807`, `12.3`, `-12.3`, `720368.54775807`, `720368.547758075`,
|
||||
`1e1`, `1e+1`, `1e-1`, `1E1`, `1E+1`, `1E-1`, `-1e1`, `-1e+1`, `-1e-1`,
|
||||
}
|
||||
for _, input := range inputs {
|
||||
// non-streaming
|
||||
t.Run(fmt.Sprintf("%v", input), func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user