diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 028001127876fa545240484af7bd17ed969b9352..33aefd6631cb086db341dfc9d16b3b6a4dd8ee92 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 both possible options: LF and CRLF. + -- + 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 a03df5277882a9f517960c8706ca809b464b4542..9e8b41b84e59b0fb0026f853867cb59526aa52a5 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(70) +test:plan(72) -- Start console and connect to it local server = console.listen(CONSOLE_SOCKET) @@ -271,6 +271,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 telnet 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()" --