]> granicus.if.org Git - vim/commitdiff
patch 8.1.0223: completing shell command finds sub-directories in $PATH v8.1.0223
authorBram Moolenaar <Bram@vim.org>
Sat, 28 Jul 2018 17:20:13 +0000 (19:20 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 28 Jul 2018 17:20:13 +0000 (19:20 +0200)
Problem:    Completing shell command finds sub-directories in $PATH.
Solution:   Remove EW_DIR when completing an item in $PATH. (Jason Franklin)

src/ex_getln.c
src/testdir/test_cmdline.vim
src/version.c

index 063900a388d3295cf1b671e2233dc0157b28f922..e659c1a8c2e505c167dec6dd65a7d63f186d3542 100644 (file)
@@ -5193,16 +5193,6 @@ expand_shellcmd(
     hash_init(&found_ht);
     for (s = path; ; s = e)
     {
-       if (*s == NUL)
-       {
-           if (did_curdir)
-               break;
-           /* Find directories in the current directory, path is empty. */
-           did_curdir = TRUE;
-       }
-       else if (*s == '.')
-           did_curdir = TRUE;
-
 #if defined(MSWIN)
        e = vim_strchr(s, ';');
 #else
@@ -5211,6 +5201,23 @@ expand_shellcmd(
        if (e == NULL)
            e = s + STRLEN(s);
 
+       if (*s == NUL)
+       {
+           if (did_curdir)
+               break;
+           // Find directories in the current directory, path is empty.
+           did_curdir = TRUE;
+           flags |= EW_DIR;
+       }
+       else if (STRNCMP(s, ".", (int)(e - s)) == 0)
+       {
+           did_curdir = TRUE;
+           flags |= EW_DIR;
+       }
+       else
+           // Do not match directories inside a $PATH item.
+           flags &= ~EW_DIR;
+
        l = e - s;
        if (l > MAXPATHL - 5)
            break;
@@ -5266,8 +5273,6 @@ expand_shellcmd(
 
 
 # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
-static void * call_user_expand_func(void *(*user_expand_func)(char_u *, int, typval_T *, int), expand_T        *xp, int *num_file, char_u ***file);
-
 /*
  * Call "user_expand_func()" to invoke a user defined Vim script function and
  * return the result (either a string or a List).
index 26d33d8384c14ae31f004c1a0ca0ddf801d4b77d..f42d228e29f2b2c62a33e264190c3c4660acb45b 100644 (file)
@@ -231,7 +231,7 @@ func Test_getcompletion()
   call assert_equal([], l)
 
   let l = getcompletion('.', 'shellcmd')
-  call assert_equal(['./', '../'], l[0:1])
+  call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
   call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
   let root = has('win32') ? 'C:\\' : '/'
   let l = getcompletion(root, 'shellcmd')
@@ -290,6 +290,29 @@ func Test_getcompletion()
   call assert_fails('call getcompletion("", "burp")', 'E475:')
 endfunc
 
+func Test_shellcmd_completion()
+  let save_path = $PATH
+
+  call mkdir('Xpathdir/Xpathsubdir', 'p')
+  call writefile([''], 'Xpathdir/Xfile.exe')
+  call setfperm('Xpathdir/Xfile.exe', 'rwx------')
+
+  " Set PATH to example directory without trailing slash.
+  let $PATH = getcwd() . '/Xpathdir'
+
+  " Test for the ":!<TAB>" case.  Previously, this would include subdirs of
+  " dirs in the PATH, even though they won't be executed.  We check that only
+  " subdirs of the PWD and executables from the PATH are included in the
+  " suggestions.
+  let actual = getcompletion('X', 'shellcmd')
+  let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
+  call insert(expected, 'Xfile.exe')
+  call assert_equal(expected, actual)
+
+  call delete('Xpathdir', 'rf')
+  let $PATH = save_path
+endfunc
+
 func Test_expand_star_star()
   call mkdir('a/b', 'p')
   call writefile(['asdfasdf'], 'a/b/fileXname')
index 968ff96ad4b8e7cb29a5b7a087f8f391a2e7472a..e646a2b43230147abf96d2d0d210f769589fd154 100644 (file)
@@ -798,6 +798,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    223,
 /**/
     222,
 /**/