aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-16 17:26:14 +0800
committerGitHub <noreply@github.com>2024-03-16 17:26:14 +0800
commitee89ba1d7531b184d5abc6b311db258da26bae42 (patch)
tree479be993dacf8c9bae60c9fc2dc8123bd3593c6a
parentc0daea3afd6a1e502e282a235a10643c785301f7 (diff)
downloadrneovim-ee89ba1d7531b184d5abc6b311db258da26bae42.tar.gz
rneovim-ee89ba1d7531b184d5abc6b311db258da26bae42.tar.bz2
rneovim-ee89ba1d7531b184d5abc6b311db258da26bae42.zip
vim-patch:9.1.0182: Can define function with invalid name inside 'formatexpr' (#27883)
Problem: Can define function with invalid name inside 'formatexpr'. Solution: Use goto instead of checking for did_emsg later. (zeertzjq) closes: vim/vim#14209 https://github.com/vim/vim/commit/6a04bf5ee523b2d6d01d7290e356a30de219f465
-rw-r--r--src/nvim/eval/userfunc.c1
-rw-r--r--test/old/testdir/test_user_func.vim19
2 files changed, 20 insertions, 0 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 2ada0a0e59..27f7f42739 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -2309,6 +2309,7 @@ void ex_function(exarg_T *eap)
: eval_isnamec(name_base[i])); i++) {}
if (name_base[i] != NUL) {
emsg_funcname(e_invarg2, arg);
+ goto ret_free;
}
}
// Disallow using the g: dict.
diff --git a/test/old/testdir/test_user_func.vim b/test/old/testdir/test_user_func.vim
index fc7dcd62b8..3c24412eb7 100644
--- a/test/old/testdir/test_user_func.vim
+++ b/test/old/testdir/test_user_func.vim
@@ -891,4 +891,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