From f89972e13a489d5a897fc73f1d46b5475e5f65df Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 Jun 2026 19:58:46 +0800 Subject: [PATCH] fix(options): crash when setting option to empty dict #40492 --- src/nvim/option.c | 2 +- test/functional/api/vim_spec.lua | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nvim/option.c b/src/nvim/option.c index 84f648135d..2cc9e734be 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3650,7 +3650,7 @@ OptVal object_as_optval_for(OptIndex opt_idx, Object o, set_op_T op, bool *error } // Sort maps and comma-flag lists for a deterministic result (Dict order is unstable); a bare // flag list is concatenated in-order with no separator. - if (is_map || is_comma) { + if (ga.ga_len > 0 && (is_map || is_comma)) { sort_strings(ga.ga_data, ga.ga_len); } str = ga_concat_strings(&ga, (is_flaglist && !is_comma) ? "" : ","); diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7b81d6edef..817684846f 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -2279,9 +2279,12 @@ describe('API', function() -- only support removing items in order. Behavior matches :set-= api.nvim_set_option_value('wildignore', { '1', '2', '3' }, { operation = 'remove' }) eq('*.o,*.obj,*.a,*.b,*.c', api.nvim_get_option_value('wildignore', {})) + + api.nvim_set_option_value('wildignore', {}, {}) + eq('', api.nvim_get_option_value('wildignore', {})) end) - it('allows setting, appending, prepending, removing tables', function() + it('allows setting, appending, prepending, removing dicts', function() -- NOTE: order is dependent on lua's hash map implementation. I don't -- *think* order matters for the map style options api.nvim_set_option_value('listchars', { eol = '~', space = '-' }, {}) @@ -2307,6 +2310,9 @@ describe('API', function() -- A bare key (string or 1-item list) removes the matching "key:value" item by key. api.nvim_set_option_value('listchars', { 'space' }, { operation = 'remove' }) eq('eol:~,tab:>-', api.nvim_get_option_value('listchars', {})) + + api.nvim_set_option_value('listchars', vim.empty_dict(), {}) + eq('', api.nvim_get_option_value('listchars', {})) end) it('returns the new option value', function()