From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 85E71218EC for ; Tue, 10 Jul 2018 06:42:23 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y8YjHUzPsuyA for ; Tue, 10 Jul 2018 06:42:23 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C753220212 for ; Tue, 10 Jul 2018 06:42:22 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] app: fix parsing integers with exponent in json Date: Tue, 10 Jul 2018 13:42:18 +0300 Message-Id: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov 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