From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 dev.tarantool.org (Postfix) with ESMTPS id 7EE7F44532F for ; Thu, 16 Jul 2020 17:47:08 +0300 (MSK) From: imeevma@tarantool.org Date: Thu, 16 Jul 2020 17:47:06 +0300 Message-Id: <16ed462c242f541218ce4d60d70489704e1dbb54.1594909974.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 15/22] sql: check args of unicode() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org After this patch, the argument types of the unicode() function will be checked properly. Part of #4159 --- src/box/sql/func.c | 6 ++++- test/sql-tap/func5.test.lua | 51 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index a22c50c79..00ba7c9c2 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1389,6 +1389,10 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv) static void unicodeFunc(sql_context * context, int argc, sql_value ** argv) { + enum mp_type mp_type = sql_value_type(argv[0]); + if (mp_type == MP_NIL) + return sql_result_null(context); + assert(mp_type == MP_STR); const unsigned char *z = sql_value_text(argv[0]); (void)argc; if (z && z[0]) @@ -2915,7 +2919,7 @@ static struct { }, { .name = "UNICODE", .param_count = 1, - .first_arg = FIELD_TYPE_ANY, + .first_arg = FIELD_TYPE_STRING, .args = FIELD_TYPE_ANY, .is_blob_like_str = false, .returns = FIELD_TYPE_STRING, diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index 78b98f2b1..77105baf2 100755 --- a/test/sql-tap/func5.test.lua +++ b/test/sql-tap/func5.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(141) +test:plan(148) --!./tcltestrunner.lua -- 2010 August 27 @@ -1130,4 +1130,53 @@ test:do_catchsql_test( 1, "Type mismatch: can not convert varbinary to integer" }) +test:do_execsql_test( + "func-5-6.18.1", [[ + SELECT unicode(NULL); + ]],{ + "" + }) + +test:do_catchsql_test( + "func-5-6.18.2", [[ + SELECT unicode(123); + ]], { + 1, "Type mismatch: can not convert 123 to string" + }) + +test:do_catchsql_test( + "func-5-6.18.3", [[ + SELECT unicode(-123); + ]], { + 1, "Type mismatch: can not convert -123 to string" + }) + +test:do_catchsql_test( + "func-5-6.18.4", [[ + SELECT unicode(-5.5); + ]], { + 1, "Type mismatch: can not convert -5.5 to string" + }) + +test:do_execsql_test( + "func-5-6.18.5", [[ + SELECT unicode('-123'); + ]], { + 45 + }) + +test:do_catchsql_test( + "func-5-6.18.6", [[ + SELECT unicode(false); + ]], { + 1, "Type mismatch: can not convert FALSE to string" + }) + +test:do_catchsql_test( + "func-5-6.18.7", [[ + SELECT unicode(X'3334'); + ]], { + 1, "Type mismatch: can not convert varbinary to string" + }) + test:finish_test() -- 2.25.1