From 2f352217742cd7705582f17608e3784a88988ea5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Oct 2025 10:21:44 +0800 Subject: [PATCH] fix(excmd): :trust executed even when inside false condition (#36032) Problem: :trust is executed even when inside false condition. Solution: Make skip_cmd() return true for CMD_trust, as ex_trust() does not handle eap->skip itself. --- runtime/doc/editing.txt | 4 ++-- src/nvim/ex_docmd.c | 1 - test/functional/ex_cmds/trust_spec.lua | 16 ++++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index cb5de0f2e5..0448cd52ae 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -1714,8 +1714,8 @@ mark a file as trusted or untrusted using the |:trust| command or the contents. The trust list is stored on disk, Nvim will re-use it after restarting. - [++deny] marks [file] (or current buffer if no [file]) as - untrusted: it will never be executed, 'exrc' will + [++deny] marks [file] (or current buffer if no [file]) + as untrusted: it will never be executed, 'exrc' will ignore it. [++remove] removes [file] (or current buffer if no diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 653b4afdca..cc2d87b90e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1951,7 +1951,6 @@ static bool skip_cmd(const exarg_T *eap) case CMD_throw: case CMD_tilde: case CMD_topleft: - case CMD_trust: case CMD_unlet: case CMD_unlockvar: case CMD_verbose: diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index 2abac85fbd..f33f237c4c 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -13,21 +13,21 @@ local fn = n.fn describe(':trust', function() local xstate = 'Xstate' - setup(function() - n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - end) - - teardown(function() - n.rmdir(xstate) - end) - before_each(function() + n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) t.write_file('test_file', 'test') clear { env = { XDG_STATE_HOME = xstate } } end) after_each(function() os.remove('test_file') + n.rmdir(xstate) + end) + + it('is not executed when inside false condition', function() + command('edit test_file') + eq('', exec_capture('if 0 | trust | endif')) + eq(nil, vim.uv.fs_stat(fn.stdpath('state') .. pathsep .. 'trust')) end) it('trust then deny then remove a file using current buffer', function()