From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 751424696C4 for ; Sat, 21 Dec 2019 17:56:18 +0300 (MSK) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3594.4.19\)) From: Roman Khabibov In-Reply-To: Date: Sat, 21 Dec 2019 17:56:17 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: Subject: Re: [Tarantool-patches] [PATCH v2 1/2] json: make error messages more readable List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy commit a427872128d30bd769e63a1254af774c1a24aa28 Author: Roman Khabibov Date: Wed Oct 9 17:07:41 2019 +0300 json: make error messages more readable =20 Print tokens themselves instead of token names "T_*" in the error messages. =20 Part of #4339 diff --git a/test/app-tap/json.test.lua b/test/app-tap/json.test.lua index fadfc74ec..6d511e686 100755 --- a/test/app-tap/json.test.lua +++ b/test/app-tap/json.test.lua @@ -22,7 +22,7 @@ end =20 tap.test("json", function(test) local serializer =3D require('json') - test:plan(40) + test:plan(51) =20 test:test("unsigned", common.test_unsigned, serializer) test:test("signed", common.test_signed, serializer) @@ -154,4 +154,34 @@ tap.test("json", function(test) _, err_msg =3D pcall(serializer.decode, '{"hello": "world",\n 100: = 200}') test:ok(string.find(err_msg, 'line 2 at character 2') ~=3D nil, 'mistake on second line') + + -- + -- gh-4339: Make sure that tokens 'T_*' are absent in error + -- messages and a context is printed. + -- + _, err_msg =3D pcall(serializer.decode, '{{: "world"}') + test:ok(string.find(err_msg, '\'{\'') ~=3D nil, '"{" instead of = T_OBJ_BEGIN') + _, err_msg =3D pcall(serializer.decode, '{"a": "world"}}') + test:ok(string.find(err_msg, '\'}\'') ~=3D nil, '"}" instead of = T_OBJ_END') + _, err_msg =3D pcall(serializer.decode, '{[: "world"}') + test:ok(string.find(err_msg, '\'[\'', 1, true) ~=3D nil, + '"[" instead of T_ARR_BEGIN') + _, err_msg =3D pcall(serializer.decode, '{]: "world"}') + test:ok(string.find(err_msg, '\']\'', 1, true) ~=3D nil, + '"]" instead of T_ARR_END') + _, err_msg =3D pcall(serializer.decode, '{1: "world"}') + test:ok(string.find(err_msg, 'int') ~=3D nil, 'int instead of = T_INT') + _, err_msg =3D pcall(serializer.decode, '{1.0: "world"}') + test:ok(string.find(err_msg, 'number') ~=3D nil, 'number instead of = T_NUMBER') + _, err_msg =3D pcall(serializer.decode, '{true: "world"}') + test:ok(string.find(err_msg, 'boolean') ~=3D nil, + 'boolean instead of T_BOOLEAN') + _, err_msg =3D pcall(serializer.decode, '{null: "world"}') + test:ok(string.find(err_msg, 'null') ~=3D nil, 'null instead of = T_NULL') + _, err_msg =3D pcall(serializer.decode, '{:: "world"}') + test:ok(string.find(err_msg, 'colon') ~=3D nil, 'colon instead of = T_COLON') + _, err_msg =3D pcall(serializer.decode, '{,: "world"}') + test:ok(string.find(err_msg, 'comma') ~=3D nil, 'comma instead of = T_COMMA') + _, err_msg =3D pcall(serializer.decode, '{') + test:ok(string.find(err_msg, 'end') ~=3D nil, 'end instead of = T_END') end) diff --git a/third_party/lua-cjson/lua_cjson.c = b/third_party/lua-cjson/lua_cjson.c index 3d25814f3..e68b52847 100644 --- a/third_party/lua-cjson/lua_cjson.c +++ b/third_party/lua-cjson/lua_cjson.c @@ -72,23 +72,23 @@ typedef enum { } json_token_type_t; =20 static const char *json_token_type_name[] =3D { - "T_OBJ_BEGIN", - "T_OBJ_END", - "T_ARR_BEGIN", - "T_ARR_END", - "T_STRING", - "T_UINT", - "T_INT", - "T_NUMBER", - "T_BOOLEAN", - "T_NULL", - "T_COLON", - "T_COMMA", - "T_END", - "T_WHITESPACE", - "T_LINEFEED", - "T_ERROR", - "T_UNKNOWN", + "'{'", + "'}'", + "'['", + "']'", + "string", + "unsigned int", + "int", + "number", + "boolean", + "null", + "colon", + "comma", + "end", + "whitespace", + "line feed", + "error", + "unknown symbol", NULL }; =20 @@ -914,7 +914,7 @@ static void json_parse_object_context(lua_State *l, = json_parse_t *json) } =20 if (token.type !=3D T_COMMA) - json_throw_parse_error(l, json, "comma or object end", = &token); + json_throw_parse_error(l, json, "comma or '}'", &token); =20 json_next_token(json, &token); } @@ -954,7 +954,7 @@ static void json_parse_array_context(lua_State *l, = json_parse_t *json) } =20 if (token.type !=3D T_COMMA) - json_throw_parse_error(l, json, "comma or array end", = &token); + json_throw_parse_error(l, json, "comma or ']'", &token); =20 json_next_token(json, &token); }