[tarantool-patches] [PATCH v1 1/1] app: fix parsing integers with exponent in json
Kirill Shcherbatov
kshcherbatov at tarantool.org
Tue Jul 10 13:42:18 MSK 2018
Now it is possible to specify a number in exponential
form via all formats allowed by json standard.
json.decode('{"remained_amount":2.0e+3}')
json.decode('{"remained_amount":2.0E+3}')
json.decode('{"remained_amount":2e+3}')
json.decode('{"remained_amount":2E+3}') <-- fixed
Closes #3514.
---
https://github.com/tarantool/tarantool/issues/3514
https://github.com/tarantool/tarantool/commits/kshch/gh-3514-json-integers-with-exp
test/app/json.result | 19 +++++++++++++++++++
test/app/json.test.lua | 6 ++++++
third_party/lua-cjson/lua_cjson.c | 2 +-
3 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 test/app/json.result
create mode 100644 test/app/json.test.lua
diff --git a/test/app/json.result b/test/app/json.result
new file mode 100644
index 0000000..434e593
--- /dev/null
+++ b/test/app/json.result
@@ -0,0 +1,19 @@
+json = require('json')
+---
+...
+json.decode('{"remained_amount":2.0e+3}')
+---
+- {'remained_amount': 2000}
+...
+json.decode('{"remained_amount":2.0E+3}')
+---
+- {'remained_amount': 2000}
+...
+json.decode('{"remained_amount":2e+3}')
+---
+- {'remained_amount': 2000}
+...
+json.decode('{"remained_amount":2E+3}')
+---
+- {'remained_amount': 2000}
+...
diff --git a/test/app/json.test.lua b/test/app/json.test.lua
new file mode 100644
index 0000000..b5485ca
--- /dev/null
+++ b/test/app/json.test.lua
@@ -0,0 +1,6 @@
+json = require('json')
+
+json.decode('{"remained_amount":2.0e+3}')
+json.decode('{"remained_amount":2.0E+3}')
+json.decode('{"remained_amount":2e+3}')
+json.decode('{"remained_amount":2E+3}')
diff --git a/third_party/lua-cjson/lua_cjson.c b/third_party/lua-cjson/lua_cjson.c
index aa8217d..11aa402 100644
--- a/third_party/lua-cjson/lua_cjson.c
+++ b/third_party/lua-cjson/lua_cjson.c
@@ -700,7 +700,7 @@ static void json_next_number_token(json_parse_t *json, json_token_t *token)
token->type = T_UINT;
token->value.ival = strtoull(json->ptr, &endptr, 10);
}
- if (*endptr == '.' || *endptr == 'e') {
+ if (*endptr == '.' || *endptr == 'e' || *endptr == 'E') {
token->type = T_NUMBER;
token->value.number = fpconv_strtod(json->ptr, &endptr);
}
--
2.7.4
More information about the Tarantool-patches
mailing list