diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-11-30 07:56:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 07:56:47 +0800 |
commit | 463b577afb78ad864cd09ac2c51f77653ab4ce48 (patch) | |
tree | 94cd232a41f9d826f79bcf1851ba1b49e1d215e1 | |
parent | 65de1a22c4d94cd8591f90255bcde72e6b385e60 (diff) | |
parent | 90b213990f02d2a86019ef4058ad86a995931bea (diff) | |
download | rneovim-463b577afb78ad864cd09ac2c51f77653ab4ce48.tar.gz rneovim-463b577afb78ad864cd09ac2c51f77653ab4ce48.tar.bz2 rneovim-463b577afb78ad864cd09ac2c51f77653ab4ce48.zip |
Merge pull request #25994 from luki446/windows-path-terminal-fix
Fix a bug in usage of windows-style paths as SHELL path.
-rw-r--r-- | src/nvim/ex_docmd.c | 4 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 24 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0b466bbe4e..245121f4af 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7424,7 +7424,9 @@ static void ex_terminal(exarg_T *eap) char shell_argv[512] = { 0 }; while (*p != NULL) { - snprintf(tempstring, sizeof(tempstring), ",\"%s\"", *p); + char *escaped = vim_strsave_escaped(*p, "\"\\"); + snprintf(tempstring, sizeof(tempstring), ",\"%s\"", escaped); + xfree(escaped); xstrlcat(shell_argv, tempstring, sizeof(shell_argv)); p++; } diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index bfb8f2136c..bf0aade255 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -141,15 +141,20 @@ describe(':terminal', function() end) end) -describe(':terminal (with fake shell)', function() +local function test_terminal_with_fake_shell(backslash) + -- shell-test.c is a fake shell that prints its arguments and exits. + local shell_path = testprg('shell-test') + if backslash then + shell_path = shell_path:gsub('/', [[\]]) + end + local screen before_each(function() clear() screen = Screen.new(50, 4) screen:attach({rgb=false}) - -- shell-test.c is a fake shell that prints its arguments and exits. - nvim('set_option_value', 'shell', testprg('shell-test'), {}) + nvim('set_option_value', 'shell', shell_path, {}) nvim('set_option_value', 'shellcmdflag', 'EXE', {}) nvim('set_option_value', 'shellxquote', '', {}) end) @@ -189,7 +194,7 @@ describe(':terminal (with fake shell)', function() end) it("with no argument, but 'shell' has arguments, acts like termopen()", function() - nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {}) + nvim('set_option_value', 'shell', shell_path ..' -t jeff', {}) terminal_with_fake_shell() screen:expect([[ ^jeff $ | @@ -211,7 +216,7 @@ describe(':terminal (with fake shell)', function() end) it("executes a given command through the shell, when 'shell' has arguments", function() - nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {}) + nvim('set_option_value', 'shell', shell_path ..' -t jeff', {}) command('set shellxquote=') -- win: avoid extra quotes terminal_with_fake_shell('echo hi') screen:expect([[ @@ -304,4 +309,13 @@ describe(':terminal (with fake shell)', function() terminal]]) end end) +end + +describe(':terminal (with fake shell)', function() + test_terminal_with_fake_shell(false) + if is_os('win') then + describe("when 'shell' uses backslashes", function() + test_terminal_with_fake_shell(true) + end) + end end) |