vim-patch:8.1.1740: exepath() doesn't work for "bin/cat" (#10556)

Problem:    Exepath() doesn't work for "bin/cat".
Solution:   Check for any path separator. (Daniel Hahler, closes vim/vim#4724,
            closes vim/vim#4710)
d08b8c4c04

Fixes https://github.com/neovim/neovim/issues/10554.
This commit is contained in:
Daniel Hahler 2019-07-24 22:23:00 +02:00 committed by GitHub
parent 3566267e75
commit b8fcf62da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 17 deletions

View File

@ -8465,10 +8465,7 @@ static void f_executable(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const char *name = tv_get_string(&argvars[0]); const char *name = tv_get_string(&argvars[0]);
// Check in $PATH and also check directly if there is a directory name // Check in $PATH and also check directly if there is a directory name
rettv->vval.v_number = ( rettv->vval.v_number = os_can_exe(name, NULL, true);
os_can_exe(name, NULL, true)
|| (gettail_dir(name) != name
&& os_can_exe(name, NULL, false)));
} }
typedef struct { typedef struct {

View File

@ -242,23 +242,12 @@ int os_exepath(char *buffer, size_t *size)
bool os_can_exe(const char *name, char **abspath, bool use_path) bool os_can_exe(const char *name, char **abspath, bool use_path)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
bool no_path = !use_path || path_is_absolute((char_u *)name); if (!use_path || gettail_dir(name) != name) {
// If the filename is "qualified" (relative or absolute) do not check $PATH.
#ifdef WIN32
no_path |= (name[0] == '.'
&& ((name[1] == '/' || name[1] == '\\')
|| (name[1] == '.' && (name[2] == '/' || name[2] == '\\'))));
#else
no_path |= (name[0] == '.'
&& (name[1] == '/' || (name[1] == '.' && name[2] == '/')));
#endif
if (no_path) {
#ifdef WIN32 #ifdef WIN32
if (is_executable_ext(name, abspath)) { if (is_executable_ext(name, abspath)) {
#else #else
// Must have path separator, cannot execute files in the current directory. // Must have path separator, cannot execute files in the current directory.
if (gettail_dir(name) != name if ((use_path || gettail_dir(name) != name)
&& is_executable(name, abspath)) { && is_executable(name, abspath)) {
#endif #endif
return true; return true;

View File

@ -887,6 +887,14 @@ func Test_Executable()
elseif has('unix') elseif has('unix')
call assert_equal(1, executable('cat')) call assert_equal(1, executable('cat'))
call assert_equal(0, executable('nodogshere')) 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 endif
endfunc endfunc