Merge pull request #30015 from zeertzjq/vim-8.2.4860

vim-patch: Check NoDefaultCurrentDirectoryInExePath
This commit is contained in:
zeertzjq 2024-08-09 07:45:21 +08:00 committed by GitHub
commit b9913191be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 59 additions and 14 deletions

View File

@ -1256,8 +1256,10 @@ executable({expr}) *executable()*
This function checks if an executable with the name {expr} This function checks if an executable with the name {expr}
exists. {expr} must be the name of the program without any exists. {expr} must be the name of the program without any
arguments. arguments.
executable() uses the value of $PATH and/or the normal executable() uses the value of $PATH and/or the normal
searchpath for programs. *PATHEXT* searchpath for programs.
*PATHEXT*
On MS-Windows the ".exe", ".bat", etc. can optionally be On MS-Windows the ".exe", ".bat", etc. can optionally be
included. Then the extensions in $PATHEXT are tried. Thus if included. Then the extensions in $PATHEXT are tried. Thus if
"foo.exe" does not exist, "foo.exe.bat" can be found. If "foo.exe" does not exist, "foo.exe.bat" can be found. If
@ -1267,8 +1269,13 @@ executable({expr}) *executable()*
then the name is also tried without adding an extension. then the name is also tried without adding an extension.
On MS-Windows it only checks if the file exists and is not a On MS-Windows it only checks if the file exists and is not a
directory, not if it's really executable. directory, not if it's really executable.
On Windows an executable in the same directory as Vim is On MS-Windows an executable in the same directory as the Vim
always found (it is added to $PATH at |startup|). 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.
The result is a Number: The result is a Number:
1 exists 1 exists
0 does not exist 0 does not exist

View File

@ -1586,8 +1586,10 @@ function vim.fn.eventhandler() end
--- This function checks if an executable with the name {expr} --- This function checks if an executable with the name {expr}
--- exists. {expr} must be the name of the program without any --- exists. {expr} must be the name of the program without any
--- arguments. --- arguments.
---
--- executable() uses the value of $PATH and/or the normal --- executable() uses the value of $PATH and/or the normal
--- searchpath for programs. *PATHEXT* --- searchpath for programs.
--- *PATHEXT*
--- On MS-Windows the ".exe", ".bat", etc. can optionally be --- On MS-Windows the ".exe", ".bat", etc. can optionally be
--- included. Then the extensions in $PATHEXT are tried. Thus if --- included. Then the extensions in $PATHEXT are tried. Thus if
--- "foo.exe" does not exist, "foo.exe.bat" can be found. If --- "foo.exe" does not exist, "foo.exe.bat" can be found. If
@ -1597,8 +1599,13 @@ function vim.fn.eventhandler() end
--- then the name is also tried without adding an extension. --- then the name is also tried without adding an extension.
--- On MS-Windows it only checks if the file exists and is not a --- On MS-Windows it only checks if the file exists and is not a
--- directory, not if it's really executable. --- directory, not if it's really executable.
--- On Windows an executable in the same directory as Vim is --- On MS-Windows an executable in the same directory as the Vim
--- always found (it is added to $PATH at |startup|). --- 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.
---
--- The result is a Number: --- The result is a Number:
--- 1 exists --- 1 exists
--- 0 does not exist --- 0 does not exist

View File

@ -2059,8 +2059,10 @@ M.funcs = {
This function checks if an executable with the name {expr} This function checks if an executable with the name {expr}
exists. {expr} must be the name of the program without any exists. {expr} must be the name of the program without any
arguments. arguments.
executable() uses the value of $PATH and/or the normal executable() uses the value of $PATH and/or the normal
searchpath for programs. *PATHEXT* searchpath for programs.
*PATHEXT*
On MS-Windows the ".exe", ".bat", etc. can optionally be On MS-Windows the ".exe", ".bat", etc. can optionally be
included. Then the extensions in $PATHEXT are tried. Thus if included. Then the extensions in $PATHEXT are tried. Thus if
"foo.exe" does not exist, "foo.exe.bat" can be found. If "foo.exe" does not exist, "foo.exe.bat" can be found. If
@ -2070,8 +2072,13 @@ M.funcs = {
then the name is also tried without adding an extension. then the name is also tried without adding an extension.
On MS-Windows it only checks if the file exists and is not a On MS-Windows it only checks if the file exists and is not a
directory, not if it's really executable. directory, not if it's really executable.
On Windows an executable in the same directory as Vim is On MS-Windows an executable in the same directory as the Vim
always found (it is added to $PATH at |startup|). 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.
The result is a Number: The result is a Number:
1 exists 1 exists
0 does not exist 0 does not exist

View File

@ -17,7 +17,6 @@
#endif #endif
#include "auto/config.h" #include "auto/config.h"
#include "nvim/errors.h"
#include "nvim/os/fs.h" #include "nvim/os/fs.h"
#include "nvim/os/os_defs.h" #include "nvim/os/os_defs.h"
@ -36,6 +35,7 @@
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/ascii_defs.h" #include "nvim/ascii_defs.h"
#include "nvim/errors.h"
#include "nvim/gettext_defs.h" #include "nvim/gettext_defs.h"
#include "nvim/globals.h" #include "nvim/globals.h"
#include "nvim/log.h" #include "nvim/log.h"
@ -356,10 +356,16 @@ static bool is_executable_in_path(const char *name, char **abspath)
} }
#ifdef MSWIN #ifdef MSWIN
// Prepend ".;" to $PATH. char *path = NULL;
size_t pathlen = strlen(path_env); if (!os_env_exists("NoDefaultCurrentDirectoryInExePath")) {
char *path = memcpy(xmallocz(pathlen + 2), "." ENV_SEPSTR, 2); // Prepend ".;" to $PATH.
memcpy(path + 2, path_env, pathlen); size_t pathlen = strlen(path_env);
path = xmallocz(pathlen + 2);
memcpy(path, "." ENV_SEPSTR, 2);
memcpy(path + 2, path_env, pathlen);
} else {
path = xstrdup(path_env);
}
#else #else
char *path = xstrdup(path_env); char *path = xstrdup(path_env);
#endif #endif

View File

@ -3578,6 +3578,24 @@ func Test_isabsolutepath()
endif endif
endfunc endfunc
" Test for exepath()
func Test_exepath()
if has('win32')
call assert_notequal(exepath('cmd'), '')
let oldNoDefaultCurrentDirectoryInExePath = $NoDefaultCurrentDirectoryInExePath
call writefile(['@echo off', 'echo Evil'], 'vim-test-evil.bat')
let $NoDefaultCurrentDirectoryInExePath = ''
call assert_notequal(exepath("vim-test-evil.bat"), '')
let $NoDefaultCurrentDirectoryInExePath = '1'
call assert_equal(exepath("vim-test-evil.bat"), '')
let $NoDefaultCurrentDirectoryInExePath = oldNoDefaultCurrentDirectoryInExePath
call delete('vim-test-evil.bat')
else
call assert_notequal(exepath('sh'), '')
endif
endfunc
" Test for virtcol() " Test for virtcol()
func Test_virtcol() func Test_virtcol()
new new