]> granicus.if.org Git - vim/commitdiff
patch 8.2.4860: MS-Windows: always uses current directory for executables v8.2.4860
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Tue, 3 May 2022 10:02:28 +0000 (11:02 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 3 May 2022 10:02:28 +0000 (11:02 +0100)
Problem:    MS-Windows: always uses current directory for executables.
Solution:   Check the NoDefaultCurrentDirectoryInExePath environment variable.
            (Yasuhiro Matsumoto, closes #10341)

runtime/doc/builtin.txt
src/os_win32.c
src/testdir/test_functions.vim
src/version.c

index 1b091b16f8c3e805c3a38b507a2b7c055a4486a6..beeb7364917a419486b840d3f0e79016555d91c2 100644 (file)
@@ -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
index 53107d5301fbb048e17ac89152d075f2bec400f4..97595d6ebaab8ae5214d6a1054462f42f86a15f0 100644 (file)
@@ -2237,7 +2237,11 @@ executable_exists(char *name, char_u **path, int use_path, int use_pathext)
                retval = FALSE;
                goto theend;
            }
-           STRCPY(pathbuf, ".;");
+
+           if (mch_getenv("NoDefaultCurrentDirectoryInExePath") == NULL)
+               STRCPY(pathbuf, ".;");
+           else
+               *pathbuf = NUL;
            STRCAT(pathbuf, p);
        }
     }
index a1b9b3d2620023ab266a471d5b643119426b6673..87b3844f2b3232d3d70561b98f2f75eade6e560a 100644 (file)
@@ -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
index 5cbdf3f6195902ab99fbdba27aea29d799c3a7b3..c3ecb62554ccaf50d48dc9ab2f499edaf4170f6a 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4860,
 /**/
     4859,
 /**/