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 71738276D0 for ; Tue, 5 Mar 2019 09:41:13 -0500 (EST) 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 tWPp4rVR4L4j for ; Tue, 5 Mar 2019 09:41:13 -0500 (EST) Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 2D6F026088 for ; Tue, 5 Mar 2019 09:41:12 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v1 1/1] box: fix custom delimiter for telnet connection References: <20190305134303.ndcovkmiritgpdwp@tkn_work_nb> From: Kirill Shcherbatov Message-ID: <2065a2cd-79bc-31d9-f55e-3972de01b49a@tarantool.org> Date: Tue, 5 Mar 2019 17:41:10 +0300 MIME-Version: 1.0 In-Reply-To: <20190305134303.ndcovkmiritgpdwp@tkn_work_nb> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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, Alexander Turenko On 05.03.2019 16:43, Alexander Turenko wrote: > This patch looks good for me, except several minor things. Hi! Thank you for review. Fixed everything. ============================================ In order to give a user ability to use a delimiter symbol within a code the real delimiter is user-provided 'delim' plus "\n". Since telnet sends "\r\n" on line break, the updated expression delim + "\n" could not be found in a sequence data+delim+"\r\n", so delimiter feature did not work at all. Added delim + "\r" check along with delim + "\n", that solves the described problem and does not violate backward compatibility. Closes #2027 --- src/box/lua/console.lua | 12 +++++++++--- test/app-tap/console.test.lua | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 028001127..74e9addad 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -344,8 +344,14 @@ end -- Read command from connected client console.listen() -- local function client_read(self) - local delim = self.delimiter .. "\n" - local buf = self.client:read(delim) + -- + -- Byte sequences that come over the network and come from + -- the local client console may have a different terminal + -- character. We support bouth possible options: CR and LF. + -- + local delim_cr = self.delimiter .. "\r" + local delim_lf = self.delimiter .. "\n" + local buf = self.client:read({delimiter = {delim_lf, delim_cr}}) if buf == nil then return nil elseif buf == "" then @@ -355,7 +361,7 @@ local function client_read(self) return nil end -- remove trailing delimiter - return buf:sub(1, -#delim-1) + return buf:sub(1, -#self.delimiter-2) end -- diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua index 4f915afd7..ccd33a2d0 100755 --- a/test/app-tap/console.test.lua +++ b/test/app-tap/console.test.lua @@ -21,7 +21,7 @@ local EOL = "\n...\n" test = tap.test("console") -test:plan(59) +test:plan(61) -- Start console and connect to it local server = console.listen(CONSOLE_SOCKET) @@ -255,6 +255,18 @@ box.session.on_connect(nil, console_on_connect) box.session.on_disconnect(nil, console_on_disconnect) box.session.on_auth(nil, console_on_auth) + +-- +-- gh-2027: Fix custom delimiter for console connection. +-- +client = socket.tcp_connect("unix/", CONSOLE_SOCKET) +_ = client:read(128) +client:write("console = require('console'); console.delimiter('#');\n") +test:is(yaml.decode(client:read(EOL))[1], nil, "session type") +client:write("box.NULL#\r\n") +test:is(yaml.decode(client:read(EOL))[1], box.NULL, "test new delimiter") +client:close() + -- -- gh-2642 "box.session.type()" -- -- 2.21.0