fix(api): parse_expression crash with ident and curly

Problem: nvim_parse_expression null pointer dereference when parsing an
identifier followed by { with "highlight" parameter set to false.

Solution: only set opening_hl_idx if pstate->colors is not NULL.

Not added to parser_tests.lua as that uses highlight = true.

(cherry picked from commit 5226801be2)
This commit is contained in:
Sean Dewar
2026-01-16 00:17:59 +00:00
committed by github-actions[bot]
parent d052d22979
commit 92849eacff
2 changed files with 7 additions and 3 deletions

View File

@@ -2638,7 +2638,9 @@ viml_pexpr_parse_figure_brace_closing_error:
ADD_IDENT(do {
NEW_NODE_WITH_CUR_POS(cur_node,
kExprNodeCurlyBracesIdentifier);
cur_node->data.fig.opening_hl_idx = kv_size(*pstate->colors);
if (pstate->colors) {
cur_node->data.fig.opening_hl_idx = kv_size(*pstate->colors);
}
cur_node->data.fig.type_guesses.allow_lambda = false;
cur_node->data.fig.type_guesses.allow_dict = false;
cur_node->data.fig.type_guesses.allow_ident = true;

View File

@@ -3241,9 +3241,11 @@ describe('API', function()
end
end
it('does not crash parsing invalid VimL expression #29648', function()
it('does not crash parsing invalid VimL expression', function()
api.nvim_input(':<C-r>=')
api.nvim_input('1bork/')
api.nvim_input('1bork/') -- #29648
assert_alive()
api.nvim_parse_expression('a{b}', '', false)
assert_alive()
end)