Mercurial > vim
changeset 28672:e4de5b5193b4 v8.2.4860
patch 8.2.4860: MS-Windows: always uses current directory for executables
Commit: https://github.com/vim/vim/commit/05cf63e9bdca1ac070df3e7d9c6dfc45e68ac916
Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Date: Tue May 3 11:02:28 2022 +0100
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 #10341)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 03 May 2022 12:15:04 +0200 |
parents | 5865b00cca76 |
children | 1bb2e8f5cc4b |
files | runtime/doc/builtin.txt src/os_win32.c src/testdir/test_functions.vim src/version.c |
diffstat | 4 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2016,8 +2016,10 @@ executable({expr}) *executable()* On MS-Windows it only checks if the file exists and is not a directory, not if it's really executable. On MS-Windows an executable in the same directory as Vim is - always found. Since this directory is added to $PATH it - should also work to execute it |win32-PATH|. + normally found. Since this directory is added to $PATH it + should also work to execute it |win32-PATH|. This can be + disabled by setting the $NoDefaultCurrentDirectoryInExePath + environment variable. *NoDefaultCurrentDirectoryInExePath* The result is a Number: 1 exists 0 does not exist
--- a/src/os_win32.c +++ b/src/os_win32.c @@ -2237,7 +2237,11 @@ executable_exists(char *name, char_u **p retval = FALSE; goto theend; } - STRCPY(pathbuf, ".;"); + + if (mch_getenv("NoDefaultCurrentDirectoryInExePath") == NULL) + STRCPY(pathbuf, ".;"); + else + *pathbuf = NUL; STRCAT(pathbuf, p); } }
--- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -2906,4 +2906,22 @@ 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 + " vim: shiftwidth=2 sts=2 expandtab