mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)2efc44b3f0
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)4bfa8af141
vim-patch:8.2.1194: test failure because shell prompt differs Problem: Test failure because shell prompt differs. Solution: Set the shell prompt.a4dc6f92bb
This commit is contained in:
parent
43ec616414
commit
1aae464222
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user