Skip to content

Commit

Permalink
patch 9.1.0182: Can define function with invalid name inside 'formate…
Browse files Browse the repository at this point in the history
…xpr'

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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
zeertzjq authored and chrisbra committed Mar 16, 2024
1 parent 20eaf8b commit 6a04bf5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/testdir/test_user_func.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/userfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
182,
/**/
181,
/**/
Expand Down

0 comments on commit 6a04bf5

Please sign in to comment.