neovim

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

commit f89ca7194f484108529cbb93ef61ce45a9a277b5
parent cdfb045ea027e018f14fb2735c3fd6aaa718ae58
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon, 11 Apr 2022 11:32:15 +0800

fix(events): make v:event readonly in more events (#18070)

This makes v:event readonly in these four events:
- ChanInfo
- ChanOpen
- RecordingLeave
- TermClose
Diffstat:
Msrc/nvim/channel.c | 1+
Msrc/nvim/ops.c | 1+
Msrc/nvim/terminal.c | 1+
Mtest/functional/autocmd/autocmd_spec.lua | 32++++++++++++++++++++++++++++++++
4 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/nvim/channel.c b/src/nvim/channel.c @@ -836,6 +836,7 @@ static void set_info_event(void **argv) typval_T retval; (void)object_to_vim(DICTIONARY_OBJ(info), &retval, NULL); tv_dict_add_dict(dict, S_LEN("info"), retval.vval.v_dict); + tv_dict_set_keys_readonly(dict); apply_autocmds(event, NULL, NULL, false, curbuf); diff --git a/src/nvim/ops.c b/src/nvim/ops.c @@ -944,6 +944,7 @@ int do_record(int c) buf[0] = (char)regname; buf[1] = NUL; (void)tv_dict_add_str(dict, S_LEN("regname"), buf); + tv_dict_set_keys_readonly(dict); // Get the recorded key hits. K_SPECIAL will be escaped, this // needs to be removed again to put it in a register. exec_reg then diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c @@ -336,6 +336,7 @@ void terminal_close(Terminal *term, int status) save_v_event_T save_v_event; dict_T *dict = get_v_event(&save_v_event); tv_dict_add_nr(dict, S_LEN("status"), status); + tv_dict_set_keys_readonly(dict); apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, buf); restore_v_event(dict, &save_v_event); } diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua @@ -17,6 +17,7 @@ local command = helpers.command local exc_exec = helpers.exc_exec local exec_lua = helpers.exec_lua local curbufmeths = helpers.curbufmeths +local retry = helpers.retry local source = helpers.source describe('autocmd', function() @@ -439,6 +440,37 @@ describe('autocmd', function() ]]} end) + describe('v:event is readonly #18063', function() + it('during ChanOpen event', function() + command('autocmd ChanOpen * let v:event.info.id = 0') + funcs.jobstart({'cat'}) + retry(nil, nil, function() + eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + end) + end) + + it('during ChanOpen event', function() + command('autocmd ChanInfo * let v:event.info.id = 0') + meths.set_client_info('foo', {}, 'remote', {}, {}) + retry(nil, nil, function() + eq('E46: Cannot change read-only variable "v:event.info"', meths.get_vvar('errmsg')) + end) + end) + + it('during RecordingLeave event', function() + command([[autocmd RecordingLeave * let v:event.regname = '']]) + eq('Vim(let):E46: Cannot change read-only variable "v:event.regname"', + pcall_err(command, 'normal! qqq')) + end) + + it('during TermClose event', function() + command('autocmd TermClose * let v:event.status = 0') + command('terminal') + eq('Vim(let):E46: Cannot change read-only variable "v:event.status"', + pcall_err(command, 'bdelete!')) + end) + end) + describe('old_tests', function() it('vimscript: WinNew ++once', function() source [[