mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(editorconfig): check that buffer is valid (#23922)
Fixes: https://github.com/neovim/neovim/issues/23921
This commit is contained in:
		| @@ -208,6 +208,10 @@ end | ||||
| ---@private | ||||
| function M.config(bufnr) | ||||
|   bufnr = bufnr or vim.api.nvim_get_current_buf() | ||||
|   if not vim.api.nvim_buf_is_valid(bufnr) then | ||||
|     return | ||||
|   end | ||||
|  | ||||
|   local path = vim.fs.normalize(vim.api.nvim_buf_get_name(bufnr)) | ||||
|   if vim.bo[bufnr].buftype ~= '' or not vim.bo[bufnr].modifiable or path == '' then | ||||
|     return | ||||
|   | ||||
| @@ -5,6 +5,7 @@ local eq = helpers.eq | ||||
| local pathsep = helpers.get_pathsep() | ||||
| local funcs = helpers.funcs | ||||
| local meths = helpers.meths | ||||
| local exec_lua = helpers.exec_lua | ||||
|  | ||||
| local testdir = 'Xtest-editorconfig' | ||||
|  | ||||
| @@ -206,4 +207,15 @@ But not this one | ||||
|     test_case('3_space.txt', { shiftwidth = 42 }) | ||||
|     test_case('4_space.py', { shiftwidth = 4 }) | ||||
|   end) | ||||
|  | ||||
|   it('does not operate on invalid buffers', function() | ||||
|     local ok, err = unpack(exec_lua([[ | ||||
|       vim.cmd.edit('test.txt') | ||||
|       local bufnr = vim.api.nvim_get_current_buf() | ||||
|       vim.cmd.bwipeout(bufnr) | ||||
|       return {pcall(require('editorconfig').config, bufnr)} | ||||
|     ]])) | ||||
|  | ||||
|     eq(true, ok, err) | ||||
|   end) | ||||
| end) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Gregory Anders
					Gregory Anders