diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt index e91dad1e2b..a98e00d826 100644 --- a/runtime/doc/vimfn.txt +++ b/runtime/doc/vimfn.txt @@ -1875,10 +1875,12 @@ executable({expr}) *executable()* On MS-Windows an executable in the same directory as the Vim executable is always found (it's added to $PATH at |startup|). *NoDefaultCurrentDirectoryInExePath* - On MS-Windows an executable in Vim's current working directory - is also normally found, but this can be disabled by setting - the `$NoDefaultCurrentDirectoryInExePath` environment variable. - This is always done for |:!| commands, for security reasons. + On MS-Windows when using cmd.exe as 'shell' an executable in + Vim's current working directory is also normally found, which + can be disabled by setting the + `$NoDefaultCurrentDirectoryInExePath` environment variable. + This is always done when executing external commands using + e.g. |:!|, |:make|, |system()| for security reasons. The result is a Number: 1 exists diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index fc8b1e218f..91a1a57fa1 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -1650,10 +1650,12 @@ function vim.fn.eventhandler() end --- On MS-Windows an executable in the same directory as the Vim --- executable is always found (it's added to $PATH at |startup|). --- *NoDefaultCurrentDirectoryInExePath* ---- On MS-Windows an executable in Vim's current working directory ---- is also normally found, but this can be disabled by setting ---- the `$NoDefaultCurrentDirectoryInExePath` environment variable. ---- This is always done for |:!| commands, for security reasons. +--- On MS-Windows when using cmd.exe as 'shell' an executable in +--- Vim's current working directory is also normally found, which +--- can be disabled by setting the +--- `$NoDefaultCurrentDirectoryInExePath` environment variable. +--- This is always done when executing external commands using +--- e.g. |:!|, |:make|, |system()| for security reasons. --- --- The result is a Number: --- 1 exists diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 5b36e6c4b7..b943629299 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -2161,10 +2161,12 @@ M.funcs = { On MS-Windows an executable in the same directory as the Vim executable is always found (it's added to $PATH at |startup|). *NoDefaultCurrentDirectoryInExePath* - On MS-Windows an executable in Vim's current working directory - is also normally found, but this can be disabled by setting - the `$NoDefaultCurrentDirectoryInExePath` environment variable. - This is always done for |:!| commands, for security reasons. + On MS-Windows when using cmd.exe as 'shell' an executable in + Vim's current working directory is also normally found, which + can be disabled by setting the + `$NoDefaultCurrentDirectoryInExePath` environment variable. + This is always done when executing external commands using + e.g. |:!|, |:make|, |system()| for security reasons. The result is a Number: 1 exists diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4ffd783a5b..ecd013c4e2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -355,7 +355,8 @@ static bool is_executable_in_path(const char *name, char **abspath) #ifdef MSWIN char *path = NULL; - if (!os_env_exists("NoDefaultCurrentDirectoryInExePath", false)) { + if (!os_env_exists("NoDefaultCurrentDirectoryInExePath", false) + && strstr(path_tail(p_sh), "cmd.exe") != NULL) { // Prepend ".;" to $PATH. size_t pathlen = strlen(path_env); path = xmallocz(pathlen + 2); diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua index e5530926c4..a66f9cdb8a 100644 --- a/test/functional/vimscript/executable_spec.lua +++ b/test/functional/vimscript/executable_spec.lua @@ -202,9 +202,9 @@ describe('executable() (Windows)', function() clear({ env = { PATHEXT = '' } }) command('set shell=sh') for _, ext in ipairs(exts) do - eq(1, call('executable', 'test_executable_' .. ext .. '.' .. ext)) + eq(0, call('executable', 'test_executable_' .. ext .. '.' .. ext)) end - eq(1, call('executable', 'test_executable_zzz.zzz')) + eq(0, call('executable', 'test_executable_zzz.zzz')) end) it("relative path, Unix-style 'shell' (backslashes)", function()