]> granicus.if.org Git - vim/commitdiff
patch 8.1.1740: exepath() doesn't work for "bin/cat" v8.1.1740
authorBram Moolenaar <Bram@vim.org>
Wed, 24 Jul 2019 12:59:45 +0000 (14:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 24 Jul 2019 12:59:45 +0000 (14:59 +0200)
Problem:    Exepath() doesn't work for "bin/cat".
Solution:   Check for any path separator. (Daniel Hahler, closes #4724,
            closes #4710)

src/evalfunc.c
src/os_unix.c
src/testdir/test_functions.vim
src/version.c

index 3fbeec26cfd5b89f43aa7e99894774e69e352191..8b9fba02c24305ab60b8a1a85b72d9f607336b7c 100644 (file)
@@ -3058,8 +3058,7 @@ f_executable(typval_T *argvars, typval_T *rettv)
     char_u *name = tv_get_string(&argvars[0]);
 
     /* Check in $PATH and also check directly if there is a directory name. */
-    rettv->vval.v_number = mch_can_exe(name, NULL, TRUE)
-                || (gettail(name) != name && mch_can_exe(name, NULL, FALSE));
+    rettv->vval.v_number = mch_can_exe(name, NULL, TRUE);
 }
 
 static garray_T        redir_execute_ga;
index a15d66057fe56d2ab1d470194cdc5b8fac37fdbd..6387a7757a0c5286944628c4b4c742d3f68d6b37 100644 (file)
@@ -3103,12 +3103,11 @@ mch_can_exe(char_u *name, char_u **path, int use_path)
 
     /* When "use_path" is false and if it's an absolute or relative path don't
      * need to use $PATH. */
-    if (!use_path || mch_isFullName(name) || (name[0] == '.'
-                  && (name[1] == '/' || (name[1] == '.' && name[2] == '/'))))
+    if (!use_path || gettail(name) != name)
     {
        /* There must be a path separator, files in the current directory
         * can't be executed. */
-       if (gettail(name) != name && executable_file(name))
+       if ((use_path || gettail(name) != name) && executable_file(name))
        {
            if (path != NULL)
            {
index 9199ba7ce7c33eb13181b4f0d158310a3d80d570..1833113b81bd7e2b987cfcc7bacb5a6e352609bc 100644 (file)
@@ -990,6 +990,14 @@ func Test_Executable()
   elseif has('unix')
     call assert_equal(1, executable('cat'))
     call assert_equal(0, executable('nodogshere'))
+
+    " get "cat" path and remove the leading /
+    let catcmd = exepath('cat')[1:]
+    new
+    lcd /
+    call assert_equal(1, executable(catcmd))
+    call assert_equal('/' .. catcmd, exepath(catcmd))
+    bwipe
   endif
 endfunc
 
index cc86468e6301ad9a1ca3221bc43a3fb7fa40e328..e25be558ec2e0d5aa3a554ca9d2abf1eee105a10 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1740,
 /**/
     1739,
 /**/