aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-10-03 02:52:15 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-11-23 07:45:24 -0500
commit1aae46422242677c6cc23438537b70444436e5ce (patch)
tree6938d321f96d97715fc63f19d1d3d2570b0e8e30 /src
parent43ec616414c7f17585e8b4a7e34acaaedfff5121 (diff)
downloadrneovim-1aae46422242677c6cc23438537b70444436e5ce.tar.gz
rneovim-1aae46422242677c6cc23438537b70444436e5ce.tar.bz2
rneovim-1aae46422242677c6cc23438537b70444436e5ce.zip
vim-patch:8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Problem: MS-Windows: shell commands fail if &shell contains a space. Solution: Use quotes instead of escaping. (closes vim/vim#4920) https://github.com/vim/vim/commit/2efc44b3f0b6bd8307cb281af095e08e15ab1c24 Always double-quote &shell if it contains a space. Neovim does not support escaping space with backslash, unlike Vim. N/A patches for version.c: vim-patch:8.0.1455: if $SHELL contains a space then 'shell' is incorrect Problem: If $SHELL contains a space then the default value of 'shell' is incorrect. (Matthew Horan) Solution: Escape spaces in $SHELL. (Christian Brabandt, closes vim/vim#459) https://github.com/vim/vim/commit/4bfa8af14142e54f509048239f4e8596911f56aa vim-patch:8.2.1194: test failure because shell prompt differs Problem: Test failure because shell prompt differs. Solution: Set the shell prompt. https://github.com/vim/vim/commit/a4dc6f92bb29b00783f8945bbe1101e837b6ad3c
Diffstat (limited to 'src')
-rw-r--r--src/nvim/option.c16
-rw-r--r--src/nvim/testdir/test_startup.vim21
-rw-r--r--src/nvim/testdir/test_system.vim54
3 files changed, 86 insertions, 5 deletions
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_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