diff options
| author | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2025-05-09 00:26:07 +0100 |
|---|---|---|
| committer | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2026-01-15 20:08:45 +0000 |
| commit | 3cb462a9608f67fca3873e4ade1cd552d0220c44 (patch) | |
| tree | 9dcb32cdc60a9c2f1ac73fa6c1ff6b04a0605a53 /test/functional/api/vim_spec.lua | |
| parent | 6082b7f850b592a9d2e3a55b00b22dc862ad1858 (diff) | |
| download | rneovim-3cb462a9608f67fca3873e4ade1cd552d0220c44.tar.gz rneovim-3cb462a9608f67fca3873e4ade1cd552d0220c44.tar.bz2 rneovim-3cb462a9608f67fca3873e4ade1cd552d0220c44.zip | |
fix(api): autocmds mess up nvim_get_option_value's dummy buffer
Problem: When the "filetype" key is set for nvim_get_option_value, autocommands
can crash Nvim by prematurely wiping the dummy buffer, or cause options intended
for it to instead be set for unrelated buffers if switched during OptionSet.
Solution: Don't crash. Also quash side-effects from setting the buffer options.
Diffstat (limited to 'test/functional/api/vim_spec.lua')
| -rw-r--r-- | test/functional/api/vim_spec.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6039d7196e..323b66ecbc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1977,6 +1977,42 @@ describe('API', function() ]]) eq(false, api.nvim_get_option_value('modified', {})) end) + + it('errors if autocmds wipe the dummy buffer', function() + -- Wipe the dummy buffer. This will throw E813, but the buffer will still be wiped; check that + -- such errors from setting the filetype have priority. + command 'autocmd FileType * ++once bwipeout!' + eq( + 'FileType Autocommands for "*": Vim(bwipeout):E813: Cannot close autocmd window', + pcall_err(api.nvim_get_option_value, 'formatexpr', { filetype = 'lua' }) + ) + + -- Silence E813 to check that the error for wiping the dummy buffer is set. + command 'autocmd FileType * ++once silent! bwipeout!' + eq( + 'Internal buffer was deleted', + pcall_err(api.nvim_get_option_value, 'formatexpr', { filetype = 'lua' }) + ) + end) + + it('sets dummy buffer options without side-effects', function() + exec [[ + let g:events = [] + autocmd OptionSet * let g:events += [expand("<amatch>")] + autocmd FileType * ++once let g:bufhidden = &l:bufhidden + \| let g:buftype = &l:buftype + \| let g:swapfile = &l:swapfile + \| let g:modeline = &l:modeline + \| let g:bufloaded = bufloaded(bufnr()) + ]] + api.nvim_get_option_value('formatexpr', { filetype = 'lua' }) + eq({}, eval('g:events')) + eq('hide', eval('g:bufhidden')) + eq('nofile', eval('g:buftype')) + eq(0, eval('g:swapfile')) + eq(0, eval('g:modeline')) + eq(1, eval('g:bufloaded')) + end) end) describe('nvim_{get,set}_current_buf, nvim_list_bufs', function() |