neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit acbfbbb649c39694c3a6a92160984db2fcb6f3ec
parent 9eaae3d56b8d44907da3286084d3ee7b50fe7a07
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Thu, 27 Oct 2022 09:44:13 +0800

vim-patch:8.2.3408: can delete a numbered function

Problem:    Can delete a numbered function. (Naohiro Ono)
Solution:   Disallow deleting a numbered function. (closes vim/vim#8760)

https://github.com/vim/vim/commit/ddfc05100a29263a682dd96bb924dfde4354a654

Co-authored-by: Bram Moolenaar <Bram@vim.org>

Diffstat:
Msrc/nvim/eval/userfunc.c | 7+++++++
Msrc/nvim/testdir/test_user_func.vim | 5+++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c @@ -2704,6 +2704,13 @@ void ex_delfunction(exarg_T *eap) *p = NUL; } + if (isdigit(*name) && fudi.fd_dict == NULL) { + if (!eap->skip) { + semsg(_(e_invarg2), eap->arg); + } + xfree(name); + return; + } if (!eap->skip) { fp = find_func(name); } diff --git a/src/nvim/testdir/test_user_func.vim b/src/nvim/testdir/test_user_func.vim @@ -423,6 +423,11 @@ func Test_del_func() func d.fn() return 1 endfunc + + " cannot delete the dict function by number + let nr = substitute(execute('echo d'), '.*function(''\(\d\+\)'').*', '\1', '') + call assert_fails('delfunction g:' .. nr, 'E475: Invalid argument: g:') + delfunc d.fn call assert_equal({'a' : 10}, d) endfunc