vim-patch:8.2.4860: MS-Windows: always uses current directory for executables

Problem:    MS-Windows: always uses current directory for executables.
Solution:   Check the NoDefaultCurrentDirectoryInExePath environment variable.
            (Yasuhiro Matsumoto, closes vim/vim#10341)

05cf63e9bd

Omit doc change: override in later doc update.

Co-authored-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
This commit is contained in:
zeertzjq 2024-08-09 06:57:17 +08:00
parent a89088b7a0
commit 336ab2682e
2 changed files with 29 additions and 5 deletions

View File

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

View File

@ -3578,6 +3578,24 @@ func Test_isabsolutepath()
endif
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()
func Test_virtcol()
new