diff options
author | wmin0 <wmin0@cobinhood.com> | 2019-02-18 18:52:06 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:04 +0800 |
commit | b0b312ad26e9fbe855c713a2a9827b3cd665acf3 (patch) | |
tree | 021a76ff258d4cd66ae9a271e744e568a9dad3ea | |
parent | 156e8c3e6a06a7ba3fc35ac7dd1162493090ce29 (diff) | |
download | dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar.gz dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar.bz2 dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar.lz dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar.xz dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.tar.zst dexon-b0b312ad26e9fbe855c713a2a9827b3cd665acf3.zip |
core: vm: sqlvm: parser: toDecimal handle .0
To cover the pitfall of decimal.fromString, we need to add leading 0 at
'^\.[0-9]+' case.
-rw-r--r-- | core/vm/sqlvm/parser/parser.go | 3 | ||||
-rw-r--r-- | core/vm/sqlvm/parser/parser_test.go | 1 |
2 files changed, 4 insertions, 0 deletions
diff --git a/core/vm/sqlvm/parser/parser.go b/core/vm/sqlvm/parser/parser.go index 76fa15cdc..2e882ea3c 100644 --- a/core/vm/sqlvm/parser/parser.go +++ b/core/vm/sqlvm/parser/parser.go @@ -95,6 +95,9 @@ func toUint(b []byte) (uint32, errors.ErrorCode) { } func toDecimal(b []byte) (decimal.Decimal, errors.ErrorCode) { + if len(b) > 0 && b[0] == byte('.') { + b = append([]byte{'0'}, b...) + } d, err := decimal.NewFromString(string(b)) return d, convertDecimalError(err) } diff --git a/core/vm/sqlvm/parser/parser_test.go b/core/vm/sqlvm/parser/parser_test.go index 77c3c16ff..bed734c60 100644 --- a/core/vm/sqlvm/parser/parser_test.go +++ b/core/vm/sqlvm/parser/parser_test.go @@ -22,6 +22,7 @@ func (s *ParserTestSuite) TestParse() { // Test expr. s.requireParseNoError(`select 1 + 2 * 3`) + s.requireParseNoError(`select .0`) s.requireParseNoError(`select a(1 + 1)`) s.requireParseNoError(`select hEx'12'`) s.requireParseNoError(`select x'12'`) |