]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4667: expandcmd() fails on an error v8.2.4667
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 2 Apr 2022 20:12:21 +0000 (21:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 2 Apr 2022 20:12:21 +0000 (21:12 +0100)
Problem:    expandcmd() fails on an error.
Solution:   On failure return the command unmodified. (yegappan Lakshmanan,
            closes #10063)

runtime/doc/builtin.txt
src/evalfunc.c
src/testdir/test_expand.vim
src/version.c

index ba741e23a401c823f33d276ecb9a17fc3eab40b2..f2e98298df26226b51a9d825c2e42f1190a2b057 100644 (file)
@@ -2299,10 +2299,13 @@ expandcmd({string})                                     *expandcmd()*
                like with |expand()|, and environment variables, anywhere in
                {string}.  "~user" and "~/path" are only expanded at the
                start.
-               Returns the expanded string.  Example: >
+               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|: >
+               Can also be used as a |method|: >
                        GetCommand()->expandcmd()
 <
 extend({expr1}, {expr2} [, {expr3}])                   *extend()*
index 39a2fd276652621b45efdc98e5ac85a07baad252..60ca50a111709968872d1fd4d1986e5efeceac8d 100644 (file)
@@ -4168,9 +4168,9 @@ f_expandcmd(typval_T *argvars, typval_T *rettv)
     eap.nextcmd = NULL;
     eap.cmdidx = CMD_USER;
 
+    ++emsg_off;
     expand_filename(&eap, &cmdstr, &errormsg);
-    if (errormsg != NULL && *errormsg != NUL)
-       emsg(errormsg);
+    --emsg_off;
 
     rettv->vval.v_string = cmdstr;
 }
@@ -4444,8 +4444,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref)
                    arg_idx = 0;
                else if (list->lv_len > MAX_FUNC_ARGS)
                {
-                   emsg_funcname((char *)e_too_many_arguments_for_function_str,
-                                                                           s);
+                   emsg_funcname(e_too_many_arguments_for_function_str, s);
                    vim_free(name);
                    goto theend;
                }
index e68d55e1050006579e0de4b2577b29000504c62b..ce414e4b11bcfd1a1db50018cb692f3949cd8780 100644 (file)
@@ -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 <afile>")', 'E495:')
-  call assert_fails('call expandcmd("make <afile>")', 'E495:')
+  call assert_equal('make <afile>', expandcmd("make <afile>"))
+  call assert_equal('make <amatch>', expandcmd("make <amatch>"))
+  call assert_equal('make <abuf>', expandcmd("make <abuf>"))
   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 <cfile>'))
@@ -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 <sfile>, <slnum> and <sflnum> outside of sourcing a script
 func Test_source_sfile()
   let lines =<< trim [SCRIPT]
-    :call assert_fails('echo expandcmd("<sfile>")', 'E498:')
-    :call assert_fails('echo expandcmd("<slnum>")', 'E842:')
-    :call assert_fails('echo expandcmd("<sflnum>")', 'E961:')
-    :call assert_fails('call expandcmd("edit <cfile>")', 'E446:')
-    :call assert_fails('call expandcmd("edit #")', 'E194:')
-    :call assert_fails('call expandcmd("edit #<2")', 'E684:')
-    :call assert_fails('call expandcmd("edit <cword>")', 'E348:')
-    :call assert_fails('call expandcmd("edit <cexpr>")', 'E348:')
+    :call assert_equal('<sfile>', expandcmd("<sfile>"))
+    :call assert_equal('<slnum>', expandcmd("<slnum>"))
+    :call assert_equal('<sflnum>', expandcmd("<sflnum>"))
+    :call assert_equal('edit <cfile>', expandcmd("edit <cfile>"))
+    :call assert_equal('edit #', expandcmd("edit #"))
+    :call assert_equal('edit #<2', expandcmd("edit #<2"))
+    :call assert_equal('edit <cword>', expandcmd("edit <cword>"))
+    :call assert_equal('edit <cexpr>', expandcmd("edit <cexpr>"))
     :call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:')
     :call writefile(v:errors, 'Xresult')
     :qall!
index b6fd0474eebf173c81c98ecf1edda29dd1cdac06..67427039c23ccfd98653225998b56f1524715c1f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4667,
 /**/
     4666,
 /**/