diff --git a/changelogs/unreleased/gh-5064-ignore-i-flag-without-tty.md b/changelogs/unreleased/gh-5064-ignore-i-flag-without-tty.md new file mode 100644 index 0000000000000000000000000000000000000000..5b9ac622821a062e94cb0d42a954496cfbe95b87 --- /dev/null +++ b/changelogs/unreleased/gh-5064-ignore-i-flag-without-tty.md @@ -0,0 +1,3 @@ +## bugfix/console + +* Fixed console ignoring `-i` flag in case stdin is not a tty (gh-5064). diff --git a/src/lua/init.c b/src/lua/init.c index d3a265eb8cd2b425bb6ed1a0cbcf6f8d382d67f6..ee132ca493843df0aad35c0b457cc996527619ae 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -936,7 +936,8 @@ run_script_f(va_list ap) goto luajit_error; if (lua_main(L, argc, argv) != 0) goto error; - } else if (!is_a_tty || (path && strcmp(path, "-") == 0)) { + } else if ((!interactive && !is_a_tty) || + (path && strcmp(path, "-") == 0)) { /* Execute stdin */ if (luaL_loadfile(L, NULL) != 0) goto luajit_error; diff --git a/test/app-luatest/gh_5064_console_ignore_i_flag_without_tty_test.lua b/test/app-luatest/gh_5064_console_ignore_i_flag_without_tty_test.lua new file mode 100644 index 0000000000000000000000000000000000000000..c578d2869931e40046ea769c582e54b7d300b902 --- /dev/null +++ b/test/app-luatest/gh_5064_console_ignore_i_flag_without_tty_test.lua @@ -0,0 +1,22 @@ +local t = require('luatest') +local g = t.group() + +local result_str = [[tarantool> 42 +--- +- 42 +... + +tarantool> ]] + +local TARANTOOL_PATH = arg[-1] + +g.test_console_ignores_i_flag_without_tty = function() + local cmd = [[printf '42\n' | ]] .. TARANTOOL_PATH .. [[ -i 2>/dev/null]] + local fh = io.popen(cmd, 'r') + + -- Readline on CentOS 7 produces \e[?1034h escape sequence before tarantool> prompt, remove it. + local result = fh:read('*a'):gsub('\x1b%[%?1034h', '') + + fh:close() + t.assert_equals(result, result_str) +end