To: vim_dev@googlegroups.com Subject: Patch 8.2.4667 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4667 Problem: expandcmd() fails on an error. Solution: On failure return the command unmodified. (yegappan Lakshmanan, closes #10063) Files: runtime/doc/builtin.txt, src/evalfunc.c, src/testdir/test_expand.vim *** ../vim-8.2.4666/runtime/doc/builtin.txt 2022-03-24 11:22:07.215294108 +0000 --- runtime/doc/builtin.txt 2022-04-02 21:02:02.823220632 +0100 *************** *** 2292,2301 **** like with |expand()|, and environment variables, anywhere in {string}. "~user" and "~/path" are only expanded at the start. ! Returns the expanded string. Example: > :echo expandcmd('make %<.o') ! < Can also be used as a |method|: > GetCommand()->expandcmd() < extend({expr1}, {expr2} [, {expr3}]) *extend()* --- 2299,2311 ---- like with |expand()|, and environment variables, anywhere in {string}. "~user" and "~/path" are only expanded at the start. ! Returns the expanded string. If an error is encountered ! during expansion, the unmodified {string} is returned. ! Example: > :echo expandcmd('make %<.o') + < make /path/runtime/doc/builtin.o ~ ! Can also be used as a |method|: > GetCommand()->expandcmd() < extend({expr1}, {expr2} [, {expr3}]) *extend()* *** ../vim-8.2.4666/src/evalfunc.c 2022-03-06 14:27:06.491895687 +0000 --- src/evalfunc.c 2022-04-02 21:02:34.291169227 +0100 *************** *** 4168,4176 **** eap.nextcmd = NULL; eap.cmdidx = CMD_USER; expand_filename(&eap, &cmdstr, &errormsg); ! if (errormsg != NULL && *errormsg != NUL) ! emsg(errormsg); rettv->vval.v_string = cmdstr; } --- 4168,4176 ---- eap.nextcmd = NULL; eap.cmdidx = CMD_USER; + ++emsg_off; expand_filename(&eap, &cmdstr, &errormsg); ! --emsg_off; rettv->vval.v_string = cmdstr; } *************** *** 4444,4451 **** arg_idx = 0; else if (list->lv_len > MAX_FUNC_ARGS) { ! emsg_funcname((char *)e_too_many_arguments_for_function_str, ! s); vim_free(name); goto theend; } --- 4444,4450 ---- arg_idx = 0; else if (list->lv_len > MAX_FUNC_ARGS) { ! emsg_funcname(e_too_many_arguments_for_function_str, s); vim_free(name); goto theend; } *** ../vim-8.2.4666/src/testdir/test_expand.vim 2021-11-19 12:37:31.991899942 +0000 --- src/testdir/test_expand.vim 2022-04-02 21:02:34.291169227 +0100 *************** *** 78,87 **** 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:') enew ! call assert_fails('call expandcmd("make %")', 'E499:') let $FOO="blue\tsky" call setline(1, "$FOO") call assert_equal("grep pat blue\tsky", expandcmd('grep pat ')) --- 78,88 ---- edit a1a2a3.rb call assert_equal('make b1b2b3.rb a1a2a3 Xfile.o', expandcmd('make %:gs?a?b? %< #<.o')) ! call assert_equal('make ', expandcmd("make ")) ! call assert_equal('make ', expandcmd("make ")) ! call assert_equal('make ', expandcmd("make ")) enew ! 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,99 **** --- 95,105 ---- 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,114 **** " 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_fails('autocmd User MyCmd echo ""', 'E498:') :call writefile(v:errors, 'Xresult') :qall! --- 107,120 ---- " Test for expanding , and outside of sourcing a script func Test_source_sfile() let lines =<< trim [SCRIPT] ! :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! *** ../vim-8.2.4666/src/version.c 2022-04-02 19:43:53.931491819 +0100 --- src/version.c 2022-04-02 21:09:01.902847497 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4667, /**/ -- Veni, Vidi, VW -- I came, I saw, I drove around in a little car. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///