mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
vim-patch:8.1.0223: completing shell command finds sub-directories in $PATH
Problem: Completing shell command finds sub-directories in $PATH.
Solution: Remove EW_DIR when completing an item in $PATH. (Jason Franklin)
6ab9e429da
This commit is contained in:
@@ -5008,19 +5008,24 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
|
|||||||
hashtab_T found_ht;
|
hashtab_T found_ht;
|
||||||
hash_init(&found_ht);
|
hash_init(&found_ht);
|
||||||
for (s = path; ; s = e) {
|
for (s = path; ; s = e) {
|
||||||
|
e = vim_strchr(s, ENV_SEPCHAR);
|
||||||
|
if (e == NULL) {
|
||||||
|
e = s + STRLEN(s);
|
||||||
|
}
|
||||||
|
|
||||||
if (*s == NUL) {
|
if (*s == NUL) {
|
||||||
if (did_curdir) {
|
if (did_curdir) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Find directories in the current directory, path is empty.
|
// Find directories in the current directory, path is empty.
|
||||||
did_curdir = true;
|
did_curdir = true;
|
||||||
} else if (*s == '.') {
|
flags |= EW_DIR;
|
||||||
|
} else if (STRNCMP(s, ".", e - s) == 0) {
|
||||||
did_curdir = true;
|
did_curdir = true;
|
||||||
}
|
flags |= EW_DIR;
|
||||||
|
} else {
|
||||||
e = vim_strchr(s, ENV_SEPCHAR);
|
// Do not match directories inside a $PATH item.
|
||||||
if (e == NULL) {
|
flags &= ~EW_DIR;
|
||||||
e = s + STRLEN(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l = (size_t)(e - s);
|
l = (size_t)(e - s);
|
||||||
|
@@ -301,7 +301,7 @@ func Test_getcompletion()
|
|||||||
call assert_equal([], l)
|
call assert_equal([], l)
|
||||||
|
|
||||||
let l = getcompletion('.', 'shellcmd')
|
let l = getcompletion('.', 'shellcmd')
|
||||||
call assert_equal(['./', '../'], l[0:1])
|
call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
|
||||||
call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
|
call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
|
||||||
let root = has('win32') ? 'C:\\' : '/'
|
let root = has('win32') ? 'C:\\' : '/'
|
||||||
let l = getcompletion(root, 'shellcmd')
|
let l = getcompletion(root, 'shellcmd')
|
||||||
@@ -375,6 +375,29 @@ func Test_getcompletion()
|
|||||||
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
call assert_fails('call getcompletion("", "burp")', 'E475:')
|
||||||
endfunc
|
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()
|
func Test_expand_star_star()
|
||||||
call mkdir('a/b', 'p')
|
call mkdir('a/b', 'p')
|
||||||
call writefile(['asdfasdf'], 'a/b/fileXname')
|
call writefile(['asdfasdf'], 'a/b/fileXname')
|
||||||
|
Reference in New Issue
Block a user