From 6d6e9c5d5140ab591ea07e653d4e055606e157c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 06:47:28 +0800 Subject: vim-patch:8.2.3623: "$*" is expanded to "nonomatch" Problem: "$*" is expanded to "nonomatch". Solution: Only add "set nonomatch" when using a csh-like shell. (Christian Brabandt, closes vim/vim#9159, closes vim/vim#9153) https://github.com/vim/vim/commit/8b8d829faf04fe3706c04f7f7000054acd3254e7 Cherry-pick a line from patch 8.2.0522. --- src/nvim/os/shell.c | 14 ++++++++++---- src/nvim/testdir/test_expand.vim | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index dd44cb1ce7..b793b8f9c6 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -249,10 +249,16 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } STRCAT(command, ">"); } else { - if (flags & EW_NOTFOUND) { - STRCPY(command, "set nonomatch; "); - } else { - STRCPY(command, "unset nonomatch; "); + STRCPY(command, ""); + if (shell_style == STYLE_GLOB) { + // Assume the nonomatch option is valid only for csh like shells, + // otherwise, this may set the positional parameters for the shell, + // e.g. "$*". + if (flags & EW_NOTFOUND) { + STRCAT(command, "set nonomatch; "); + } else { + STRCAT(command, "unset nonomatch; "); + } } if (shell_style == STYLE_GLOB) { STRCAT(command, "glob >"); diff --git a/src/nvim/testdir/test_expand.vim b/src/nvim/testdir/test_expand.vim index 383921bb82..e68d55e105 100644 --- a/src/nvim/testdir/test_expand.vim +++ b/src/nvim/testdir/test_expand.vim @@ -1,6 +1,7 @@ " Test for expanding file names source shared.vim +source check.vim func Test_with_directories() call mkdir('Xdir1') @@ -131,7 +132,13 @@ func Test_expand_filename_multicmd() call assert_equal(4, winnr('$')) call assert_equal('foo!', bufname(winbufnr(1))) call assert_equal('foo', bufname(winbufnr(2))) + call assert_fails('e %:s/.*//', 'E500:') %bwipe! endfunc +func Test_expandcmd_shell_nonomatch() + CheckNotMSWindows + call assert_equal('$*', expandcmd('$*')) +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 15ca01b649fb35186f1eb9b4422c36f9d8d2c8b4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 06:51:06 +0800 Subject: vim-patch:8.2.4667: expandcmd() fails on an error Problem: expandcmd() fails on an error. Solution: On failure return the command unmodified. (yegappan Lakshmanan, closes vim/vim#10063) https://github.com/vim/vim/commit/5018a836c030988944a9bbe2fd2e538bf5261a72 --- src/nvim/eval/funcs.c | 6 +++--- src/nvim/testdir/test_expand.vim | 28 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 456fd9fdf6..1798d43c6c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2052,10 +2052,10 @@ static void f_expandcmd(typval_T *argvars, typval_T *rettv, FunPtr fptr) }; eap.argt |= EX_NOSPC; + emsg_off++; expand_filename(&eap, &cmdstr, &errormsg); - if (errormsg != NULL && *errormsg != NUL) { - emsg(errormsg); - } + emsg_off--; + rettv->vval.v_string = cmdstr; } diff --git a/src/nvim/testdir/test_expand.vim b/src/nvim/testdir/test_expand.vim index e68d55e105..ce414e4b11 100644 --- a/src/nvim/testdir/test_expand.vim +++ b/src/nvim/testdir/test_expand.vim @@ -78,10 +78,11 @@ func Test_expandcmd() edit a1a2a3.rb call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) - call assert_fails('call expandcmd("make ")', 'E495:') - call assert_fails('call expandcmd("make ")', 'E495:') + call assert_equal('make ', expandcmd("make ")) + call assert_equal('make ', expandcmd("make ")) + call assert_equal('make ', expandcmd("make ")) enew - call assert_fails('call expandcmd("make %")', 'E499:') + call assert_equal('make %', expandcmd("make %")) let $FOO="blue\tsky" call setline(1, "$FOO") call assert_equal("grep pat blue\tsky", expandcmd('grep pat ')) @@ -94,6 +95,11 @@ func Test_expandcmd() let $FOO= "foo bar baz" call assert_equal("e foo bar baz", expandcmd("e $FOO")) + if has('unix') + " test for using the shell to expand a command argument + call assert_equal('{1..4}', expandcmd('{1..4}')) + endif + unlet $FOO close! endfunc @@ -101,14 +107,14 @@ endfunc " Test for expanding , and outside of sourcing a script func Test_source_sfile() let lines =<< trim [SCRIPT] - :call assert_fails('echo expandcmd("")', 'E498:') - :call assert_fails('echo expandcmd("")', 'E842:') - :call assert_fails('echo expandcmd("")', 'E961:') - :call assert_fails('call expandcmd("edit ")', 'E446:') - :call assert_fails('call expandcmd("edit #")', 'E194:') - :call assert_fails('call expandcmd("edit #<2")', 'E684:') - :call assert_fails('call expandcmd("edit ")', 'E348:') - :call assert_fails('call expandcmd("edit ")', 'E348:') + :call assert_equal('', expandcmd("")) + :call assert_equal('', expandcmd("")) + :call assert_equal('', expandcmd("")) + :call assert_equal('edit ', expandcmd("edit ")) + :call assert_equal('edit #', expandcmd("edit #")) + :call assert_equal('edit #<2', expandcmd("edit #<2")) + :call assert_equal('edit ', expandcmd("edit ")) + :call assert_equal('edit ', expandcmd("edit ")) :call assert_fails('autocmd User MyCmd echo ""', 'E498:') :call writefile(v:errors, 'Xresult') :qall! -- cgit