diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index 6a267103b4..e606322f24 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -114,7 +114,7 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err) break; case kObjectTypeInteger: group = (int)opts->group.data.integer; - char *name = augroup_name(group); + char *name = group == 0 ? NULL : augroup_name(group); VALIDATE_INT(augroup_exists(name), "group", opts->group.data.integer, { goto cleanup; }); @@ -684,7 +684,7 @@ void nvim_del_augroup_by_id(Integer id, Error *err) FUNC_API_SINCE(9) { TRY_WRAP(err, { - char *name = augroup_name((int)id); + char *name = id == 0 ? NULL : augroup_name((int)id); augroup_del(name, false); }); } @@ -746,7 +746,7 @@ void nvim_exec_autocmds(Object event, Dict(exec_autocmds) *opts, Error *err) break; case kObjectTypeInteger: au_group = (int)opts->group.data.integer; - char *name = augroup_name(au_group); + char *name = au_group == 0 ? NULL : augroup_name(au_group); VALIDATE_INT(augroup_exists(name), "group", (int64_t)au_group, { goto cleanup; }); @@ -840,7 +840,7 @@ static int get_augroup_from_object(Object group, Error *err) return au_group; case kObjectTypeInteger: au_group = (int)group.data.integer; - char *name = augroup_name(au_group); + char *name = au_group == 0 ? NULL : augroup_name(au_group); VALIDATE_INT(augroup_exists(name), "group", (int64_t)au_group, { return AUGROUP_ERROR; }); diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b1e38e77a1..57390519de 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -39,6 +39,10 @@ describe('autocmd api', function() })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, {'FileType', {}}, {})) + eq("Invalid 'group': 0", pcall_err(meths.create_autocmd, 'FileType', { + group = 0, + command = 'ls', + })) end) it('doesnt leak when you use ++once', function() @@ -308,6 +312,9 @@ describe('autocmd api', function() eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, { group = 'bogus', })) + eq("Invalid 'group': 0", pcall_err(meths.get_autocmds, { + group = 0, + })) eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, { group = {}, })) @@ -725,6 +732,9 @@ describe('autocmd api', function() eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { group = {}, })) + eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', { + group = 0, + })) eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) @@ -1049,6 +1059,12 @@ describe('autocmd api', function() eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 0)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 0)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 12342)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 12312)) end) it('groups work with once', function() @@ -1224,6 +1240,7 @@ describe('autocmd api', function() eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, { event = {'FileType', {}} })) + eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, {group = 0})) end) it('should clear based on event + pattern', function()