Mercurial > vim
diff src/testdir/test_system.vim @ 18241:85160a3649b9 v8.1.2115
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Commit: https://github.com/vim/vim/commit/2efc44b3f0b6bd8307cb281af095e08e15ab1c24
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 5 12:09:32 2019 +0200
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 https://github.com/vim/vim/issues/4920)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Oct 2019 12:15:04 +0200 |
parents | 78d4902b22df |
children | 0eeaa9a6e4e7 |
line wrap: on
line diff
--- a/src/testdir/test_system.vim +++ b/src/testdir/test_system.vim @@ -1,6 +1,7 @@ " Tests for system() and systemlist() source shared.vim +source check.vim func Test_System() if !has('win32') @@ -112,3 +113,53 @@ func Test_system_exmode() let a = system(GetVimCommand() . cmd) call assert_notequal(0, v:shell_error) endfunc + +func Test_system_with_shell_quote() + 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