aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwmin0 <wmin0@cobinhood.com>2019-02-18 18:52:06 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-03-26 17:48:21 +0800
commitab939af91954c46f4e7d8b7acf1ed0ff92d28310 (patch)
tree80ee6b422f74f20d7de5d6a100cc76dd5fa0b80c
parent33eb47ad23cdc3d8e65a2d23d1006607a902c7f9 (diff)
downloaddexon-ab939af91954c46f4e7d8b7acf1ed0ff92d28310.tar.gz
dexon-ab939af91954c46f4e7d8b7acf1ed0ff92d28310.tar.zst
dexon-ab939af91954c46f4e7d8b7acf1ed0ff92d28310.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.go3
-rw-r--r--core/vm/sqlvm/parser/parser_test.go1
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'`)