diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/v2/stdlib/json')
-rw-r--r-- | vendor/github.com/d5/tengo/v2/stdlib/json/decode.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go b/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go index 6d468ef0..557fb9ea 100644 --- a/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go +++ b/vendor/github.com/d5/tengo/v2/stdlib/json/decode.go @@ -62,9 +62,12 @@ func (d *decodeState) scanNext() { // scanWhile processes bytes in d.data[d.off:] until it // receives a scan code not equal to op. -func (d *decodeState) scanWhile(op int) { +func (d *decodeState) scanWhile(op int) (isFloat bool) { s, data, i := &d.scan, d.data, d.off for i < len(data) { + if data[i] == '.' || data[i] == 'e' || data[i] == 'E' { + isFloat = true + } newOp := s.step(s, data[i]) i++ if newOp != op { @@ -76,6 +79,7 @@ func (d *decodeState) scanWhile(op int) { d.off = len(data) + 1 // mark processed EOF with len+1 d.opcode = d.scan.eof() + return } func (d *decodeState) value() (tengo.Object, error) { @@ -185,7 +189,7 @@ func (d *decodeState) object() (tengo.Object, error) { func (d *decodeState) literal() (tengo.Object, error) { // All bytes inside literal return scanContinue op code. start := d.readIndex() - d.scanWhile(scanContinue) + isFloat := d.scanWhile(scanContinue) item := d.data[start:d.readIndex()] @@ -210,8 +214,12 @@ func (d *decodeState) literal() (tengo.Object, error) { if c != '-' && (c < '0' || c > '9') { panic(phasePanicMsg) } - n, _ := strconv.ParseFloat(string(item), 10) - return &tengo.Float{Value: n}, nil + if isFloat { + n, _ := strconv.ParseFloat(string(item), 10) + return &tengo.Float{Value: n}, nil + } + n, _ := strconv.ParseInt(string(item), 10, 64) + return &tengo.Int{Value: n}, nil } } |