diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-22 19:35:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 19:35:02 +0800 |
commit | 783b0aba411618c27cae48625f0f98e0cb503758 (patch) | |
tree | bc7cadc915244ab0c41d07f9c0e01f03f9f14563 | |
parent | f2db5521eb545e451f261470c6bfc31dfac11887 (diff) | |
download | rneovim-783b0aba411618c27cae48625f0f98e0cb503758.tar.gz rneovim-783b0aba411618c27cae48625f0f98e0cb503758.tar.bz2 rneovim-783b0aba411618c27cae48625f0f98e0cb503758.zip |
fix(completion): check that healthcheck name is string (#28458)
-rw-r--r-- | src/nvim/cmdexpand.c | 3 | ||||
-rw-r--r-- | test/functional/plugin/health_spec.lua | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index c1d219c32f..49944aa895 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2598,7 +2598,8 @@ static char *get_healthcheck_names(expand_T *xp FUNC_ATTR_UNUSED, int idx) last_gen = get_cmdline_last_prompt_id(); } - if (names.type == kObjectTypeArray && idx < (int)names.data.array.size) { + if (names.type == kObjectTypeArray && idx < (int)names.data.array.size + && names.data.array.items[idx].type == kObjectTypeString) { return names.data.array.items[idx].data.string.data; } return NULL; diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 529d182603..9c17e74e19 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,6 +6,8 @@ local curbuf_contents = t.curbuf_contents local command = t.command local eq, neq, matches = t.eq, t.neq, t.matches local getcompletion = t.fn.getcompletion +local exec_lua = t.exec_lua +local assert_alive = t.assert_alive local insert = t.insert local source = t.source local fn = t.fn @@ -20,6 +22,7 @@ describe(':checkhealth', function() eq(false, status) eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*')) end) + it("detects invalid 'runtimepath'", function() clear() command('set runtimepath=bogus') @@ -27,6 +30,7 @@ describe(':checkhealth', function() eq(false, status) eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*')) end) + it('detects invalid $VIM', function() clear() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. @@ -34,6 +38,7 @@ describe(':checkhealth', function() command('checkhealth nvim') matches('ERROR $VIM .* zub', curbuf_contents()) end) + it('completions can be listed via getcompletion()', function() clear() eq('nvim', getcompletion('nvim', 'checkhealth')[1]) @@ -41,6 +46,15 @@ describe(':checkhealth', function() eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health end) + + it('completion checks for vim.health._complete() return type #28456', function() + clear() + exec_lua([[vim.health._complete = function() return 1 end]]) + eq({}, getcompletion('', 'checkhealth')) + exec_lua([[vim.health._complete = function() return { 1 } end]]) + eq({}, getcompletion('', 'checkhealth')) + assert_alive() + end) end) describe('health.vim', function() |