mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(api): avoid assertion when autocmd group id is 0 (#23210)
This commit is contained in:
@@ -114,7 +114,7 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err)
|
|||||||
break;
|
break;
|
||||||
case kObjectTypeInteger:
|
case kObjectTypeInteger:
|
||||||
group = (int)opts->group.data.integer;
|
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, {
|
VALIDATE_INT(augroup_exists(name), "group", opts->group.data.integer, {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
});
|
});
|
||||||
@@ -684,7 +684,7 @@ void nvim_del_augroup_by_id(Integer id, Error *err)
|
|||||||
FUNC_API_SINCE(9)
|
FUNC_API_SINCE(9)
|
||||||
{
|
{
|
||||||
TRY_WRAP(err, {
|
TRY_WRAP(err, {
|
||||||
char *name = augroup_name((int)id);
|
char *name = id == 0 ? NULL : augroup_name((int)id);
|
||||||
augroup_del(name, false);
|
augroup_del(name, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -746,7 +746,7 @@ void nvim_exec_autocmds(Object event, Dict(exec_autocmds) *opts, Error *err)
|
|||||||
break;
|
break;
|
||||||
case kObjectTypeInteger:
|
case kObjectTypeInteger:
|
||||||
au_group = (int)opts->group.data.integer;
|
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, {
|
VALIDATE_INT(augroup_exists(name), "group", (int64_t)au_group, {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
});
|
});
|
||||||
@@ -840,7 +840,7 @@ static int get_augroup_from_object(Object group, Error *err)
|
|||||||
return au_group;
|
return au_group;
|
||||||
case kObjectTypeInteger:
|
case kObjectTypeInteger:
|
||||||
au_group = (int)group.data.integer;
|
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, {
|
VALIDATE_INT(augroup_exists(name), "group", (int64_t)au_group, {
|
||||||
return AUGROUP_ERROR;
|
return AUGROUP_ERROR;
|
||||||
});
|
});
|
||||||
|
@@ -39,6 +39,10 @@ describe('autocmd api', function()
|
|||||||
}))
|
}))
|
||||||
eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd,
|
eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd,
|
||||||
{'FileType', {}}, {}))
|
{'FileType', {}}, {}))
|
||||||
|
eq("Invalid 'group': 0", pcall_err(meths.create_autocmd, 'FileType', {
|
||||||
|
group = 0,
|
||||||
|
command = 'ls',
|
||||||
|
}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('doesnt leak when you use ++once', function()
|
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, {
|
eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, {
|
||||||
group = 'bogus',
|
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, {
|
eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, {
|
||||||
group = {},
|
group = {},
|
||||||
}))
|
}))
|
||||||
@@ -725,6 +732,9 @@ describe('autocmd api', function()
|
|||||||
eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', {
|
eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', {
|
||||||
group = {},
|
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', {
|
eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', {
|
||||||
buffer = {},
|
buffer = {},
|
||||||
}))
|
}))
|
||||||
@@ -1049,6 +1059,12 @@ describe('autocmd api', function()
|
|||||||
|
|
||||||
eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]])
|
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('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)
|
end)
|
||||||
|
|
||||||
it('groups work with once', function()
|
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, {
|
eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, {
|
||||||
event = {'FileType', {}}
|
event = {'FileType', {}}
|
||||||
}))
|
}))
|
||||||
|
eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, {group = 0}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('should clear based on event + pattern', function()
|
it('should clear based on event + pattern', function()
|
||||||
|
Reference in New Issue
Block a user