diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-11-23 09:19:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 09:19:11 -0500 |
commit | b155e6b54c6087fac57ea4278a3431ced7bfc7f6 (patch) | |
tree | 2060bc9e28c805bc31fa805334e8ab5139eea4e1 | |
parent | 029b5d036d7eb5a16b8e3a1d37f05f92ecf40499 (diff) | |
parent | dd3583836b80e8eccd483d41125aa24f63d2f038 (diff) | |
download | rneovim-b155e6b54c6087fac57ea4278a3431ced7bfc7f6.tar.gz rneovim-b155e6b54c6087fac57ea4278a3431ced7bfc7f6.tar.bz2 rneovim-b155e6b54c6087fac57ea4278a3431ced7bfc7f6.zip |
Merge pull request #11148 from janlazo/vim-8.0.1455
vim-patch:8.0.1455,8.1.{2115,2361}
-rw-r--r-- | runtime/doc/options.txt | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 7 | ||||
-rw-r--r-- | src/nvim/option.c | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_highlight.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_startup.vim | 21 | ||||
-rw-r--r-- | src/nvim/testdir/test_system.vim | 54 |
6 files changed, 92 insertions, 9 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index b83d2c4484..6c42dd6739 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5166,6 +5166,7 @@ A jump table for the options with a short description can be found at |Q_op|. It is allowed to give an argument to the command, e.g. "csh -f". See |option-backslash| about including spaces and backslashes. Environment variables are expanded |:set_env|. + If the name of the shell contains a space, you might need to enclose it in quotes. Example: > :set shell=\"c:\program\ files\unix\sh.exe\"\ -f diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b8a0c3184b..d2ccbe3e6d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1182,6 +1182,7 @@ static void do_filter( char_u *cmd_buf; buf_T *old_curbuf = curbuf; int shell_flags = 0; + const int stmp = p_stmp; if (*cmd == NUL) /* no filter command */ return; @@ -1210,16 +1211,16 @@ static void do_filter( if (do_out) shell_flags |= kShellOptDoOut; - if (!do_in && do_out && !p_stmp) { + if (!do_in && do_out && !stmp) { // Use a pipe to fetch stdout of the command, do not use a temp file. shell_flags |= kShellOptRead; curwin->w_cursor.lnum = line2; - } else if (do_in && !do_out && !p_stmp) { + } else if (do_in && !do_out && !stmp) { // Use a pipe to write stdin of the command, do not use a temp file. shell_flags |= kShellOptWrite; curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; - } else if (do_in && do_out && !p_stmp) { + } else if (do_in && do_out && !stmp) { // Use a pipe to write stdin and fetch stdout of the command, do not // use a temp file. shell_flags |= kShellOptRead | kShellOptWrite; diff --git a/src/nvim/option.c b/src/nvim/option.c index 146bce8cc0..6149331763 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -652,7 +652,14 @@ void set_init_1(bool clean_arg) { const char *shell = os_getenv("SHELL"); if (shell != NULL) { - set_string_default("sh", (char *) shell, false); + if (vim_strchr((const char_u *)shell, ' ') != NULL) { + const size_t len = strlen(shell) + 3; // two quotes and a trailing NUL + char *const cmd = xmalloc(len); + snprintf(cmd, len, "\"%s\"", shell); + set_string_default("sh", cmd, true); + } else { + set_string_default("sh", (char *)shell, false); + } } } @@ -987,10 +994,9 @@ static void set_string_default(const char *name, char *val, bool allocated) xfree(options[opt_idx].def_val[VI_DEFAULT]); } - options[opt_idx].def_val[VI_DEFAULT] = (char_u *) ( - allocated - ? (char_u *) val - : (char_u *) xstrdup(val)); + options[opt_idx].def_val[VI_DEFAULT] = allocated + ? (char_u *)val + : (char_u *)xstrdup(val); options[opt_idx].flags |= P_DEF_ALLOCED; } } diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index 00e42733a7..a80a73161f 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -516,7 +516,7 @@ func Test_termguicolors() if !exists('+termguicolors') return endif - if has('vtp') && !has('vcon') + if has('vtp') && !has('vcon') && !has('gui_running') " Win32: 'guicolors' doesn't work without virtual console. call assert_fails('set termguicolors', 'E954:') return diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 7fe0168356..6214975ef5 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -581,6 +581,27 @@ func Test_read_stdin() call delete('Xtestout') endfunc +func Test_set_shell() + let after =<< trim [CODE] + call writefile([&shell], "Xtestout") + quit! + [CODE] + + if has('win32') + let $SHELL = 'C:\with space\cmd.exe' + let expected = '"C:\with space\cmd.exe"' + else + let $SHELL = '/bin/with space/sh' + let expected = '"/bin/with space/sh"' + endif + + if RunVimPiped([], after, '', '') + let lines = readfile('Xtestout') + call assert_equal(expected, lines[0]) + endif + call delete('Xtestout') +endfunc + func Test_progpath() " Tests normally run with "./vim" or "../vim", these must have been expanded " to a full path. diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index d3c0594c03..424cb4abd0 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -1,5 +1,8 @@ " Tests for system() and systemlist() +source shared.vim +source check.vim + function! Test_System() if !executable('echo') || !executable('cat') || !executable('wc') return @@ -88,3 +91,54 @@ function! Test_system_exmode() let a = system(v:progpath. cmd) call assert_notequal(0, v:shell_error) endfunc + +func Test_system_with_shell_quote() + throw 'skipped: enable after porting method patches' + CheckMSWindows + + call mkdir('Xdir with spaces', 'p') + call system('copy "%COMSPEC%" "Xdir with spaces\cmd.exe"') + + let shell_save = &shell + let shellxquote_save = &shellxquote + try + " Set 'shell' always needs noshellslash. + let shellslash_save = &shellslash + set noshellslash + let shell_tests = [ + \ expand('$COMSPEC'), + \ '"' . fnamemodify('Xdir with spaces\cmd.exe', ':p') . '"', + \] + let &shellslash = shellslash_save + + let sxq_tests = ['', '(', '"'] + + " Matrix tests: 'shell' * 'shellxquote' + for shell in shell_tests + let &shell = shell + for sxq in sxq_tests + let &shellxquote = sxq + + let msg = printf('shell=%s shellxquote=%s', &shell, &shellxquote) + + try + let out = 'echo 123'->system() + catch + call assert_report(printf('%s: %s', msg, v:exception)) + continue + endtry + + " On Windows we may get a trailing space and CR. + if out != "123 \n" + call assert_equal("123\n", out, msg) + endif + + endfor + endfor + + finally + let &shell = shell_save + let &shellxquote = shellxquote_save + call delete('Xdir with spaces', 'rf') + endtry +endfunc |