]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0182: Can define function with invalid name inside 'formatexpr' v9.1.0182
authorzeertzjq <zeertzjq@outlook.com>
Sat, 16 Mar 2024 08:39:06 +0000 (09:39 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 16 Mar 2024 08:39:06 +0000 (09:39 +0100)
Problem:  Can define function with invalid name inside 'formatexpr'.
Solution: Use goto instead of checking for did_emsg later.
          (zeertzjq)

closes: #14209

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_user_func.vim
src/userfunc.c
src/version.c

index 57a093c9c95d42d90750f8a75f26c3bd12982300..992329bc7280e2319bb054f0f95722d2c480c4a7 100644 (file)
@@ -968,4 +968,23 @@ func Test_multidefer_with_exception()
   delfunc Foo
 endfunc
 
+func Test_func_curly_brace_invalid_name()
+  func Fail()
+    func Foo{'()'}bar()
+    endfunc
+  endfunc
+
+  call assert_fails('call Fail()', 'E475: Invalid argument: Foo()bar')
+
+  silent! call Fail()
+  call assert_equal([], getcompletion('Foo', 'function'))
+
+  set formatexpr=Fail()
+  normal! gqq
+  call assert_equal([], getcompletion('Foo', 'function'))
+
+  set formatexpr&
+  delfunc Fail
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 00e499fd0f123c3f8150726f29a33c3f21063c8f..ce144a397816555bbcfae5d50cdbeed4ce5b5f38 100644 (file)
@@ -4977,7 +4977,10 @@ define_function(
                                        : eval_isnamec(name_base[i])); ++i)
                ;
            if (name_base[i] != NUL)
+           {
                emsg_funcname(e_invalid_argument_str, arg);
+               goto ret_free;
+           }
 
            // In Vim9 script a function cannot have the same name as a
            // variable.
index 36c1205777d7799d6f813fb95fe7e88341a0957d..9f781963228ca23fd26a693f17d65ea930f50142 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    182,
 /**/
     181,
 /**/