mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(api): nvim_set_hl bail out on invalid group name (#20021)
This commit is contained in:
parent
0903702634
commit
fa747d004a
@ -86,8 +86,7 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err)
|
|||||||
int id = syn_name2id(name.data);
|
int id = syn_name2id(name.data);
|
||||||
|
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
api_set_error(err, kErrorTypeException, "Invalid highlight name: %s",
|
api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", name.data);
|
||||||
name.data);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = nvim_get_hl_by_id(id, rgb, err);
|
result = nvim_get_hl_by_id(id, rgb, err);
|
||||||
@ -105,8 +104,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err)
|
|||||||
{
|
{
|
||||||
Dictionary dic = ARRAY_DICT_INIT;
|
Dictionary dic = ARRAY_DICT_INIT;
|
||||||
if (syn_get_final_id((int)hl_id) == 0) {
|
if (syn_get_final_id((int)hl_id) == 0) {
|
||||||
api_set_error(err, kErrorTypeException,
|
api_set_error(err, kErrorTypeException, "Invalid highlight id: %" PRId64, hl_id);
|
||||||
"Invalid highlight id: %" PRId64, hl_id);
|
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
int attrcode = syn_id2attr((int)hl_id);
|
int attrcode = syn_id2attr((int)hl_id);
|
||||||
@ -175,6 +173,10 @@ void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err)
|
|||||||
FUNC_API_SINCE(7)
|
FUNC_API_SINCE(7)
|
||||||
{
|
{
|
||||||
int hl_id = syn_check_group(name.data, name.size);
|
int hl_id = syn_check_group(name.data, name.size);
|
||||||
|
if (hl_id == 0) {
|
||||||
|
api_set_error(err, kErrorTypeException, "Invalid highlight name: %s", name.data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int link_id = -1;
|
int link_id = -1;
|
||||||
|
|
||||||
HlAttrs attrs = dict2hlattrs(val, true, &link_id, err);
|
HlAttrs attrs = dict2hlattrs(val, true, &link_id, err);
|
||||||
|
@ -354,4 +354,9 @@ describe("API: set highlight", function()
|
|||||||
meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'})
|
meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'})
|
||||||
eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true))
|
eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('does not segfault on invalid group name #20009', function()
|
||||||
|
eq('Invalid highlight name: foo bar', pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user