diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/d5/tengo/v2/stdlib/json | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-master.tar.gz matterbridge-msglm-master.tar.bz2 matterbridge-msglm-master.zip |
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 } } |