mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
vim-patch:9.1.0566: Stop dir in findfile() doesn't work properly w/o trailing slash
Problem: Stop directory in findfile() doesn't work properly without a trailing slash. Solution: Always use fnamencmp(), not fnamecmp(). related: vim/vim#15200 related: vim/vim#15202e6ab23bd4a
(cherry picked from commit091a130804
)
This commit is contained in:
committed by
github-actions[bot]
parent
4ce293c2c3
commit
c467bfeb93
@ -880,11 +880,12 @@ char *vim_findfile(void *search_ctx_arg)
|
||||
if (search_ctx->ffsc_start_dir
|
||||
&& search_ctx->ffsc_stopdirs_v != NULL && !got_int) {
|
||||
ff_stack_T *sptr;
|
||||
// path_end may point to the NUL or the previous path separator
|
||||
ptrdiff_t plen = (path_end - search_ctx->ffsc_start_dir) + (*path_end != NUL);
|
||||
|
||||
// is the last starting directory in the stop list?
|
||||
if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
|
||||
(int)(path_end - search_ctx->ffsc_start_dir),
|
||||
search_ctx->ffsc_stopdirs_v)) {
|
||||
(size_t)plen, search_ctx->ffsc_stopdirs_v)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1219,7 +1220,7 @@ static void ff_clear(ff_search_ctx_T *search_ctx)
|
||||
/// check if the given path is in the stopdirs
|
||||
///
|
||||
/// @return true if yes else false
|
||||
static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
|
||||
static bool ff_path_in_stoplist(char *path, size_t path_len, char **stopdirs_v)
|
||||
{
|
||||
// eat up trailing path separators, except the first
|
||||
while (path_len > 1 && vim_ispathsep(path[path_len - 1])) {
|
||||
@ -1232,20 +1233,16 @@ static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
|
||||
}
|
||||
|
||||
for (int i = 0; stopdirs_v[i] != NULL; i++) {
|
||||
if ((int)strlen(stopdirs_v[i]) > path_len) {
|
||||
// match for parent directory. So '/home' also matches
|
||||
// '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
|
||||
// '/home/r' would also match '/home/rks'
|
||||
if (path_fnamencmp(stopdirs_v[i], path, (size_t)path_len) == 0
|
||||
&& vim_ispathsep(stopdirs_v[i][path_len])) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (path_fnamecmp(stopdirs_v[i], path) == 0) {
|
||||
return true;
|
||||
}
|
||||
// match for parent directory. So '/home' also matches
|
||||
// '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
|
||||
// '/home/r' would also match '/home/rks'
|
||||
if (path_fnamencmp(stopdirs_v[i], path, path_len) == 0
|
||||
&& (strlen(stopdirs_v[i]) <= path_len
|
||||
|| vim_ispathsep(stopdirs_v[i][path_len]))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -101,11 +101,18 @@ func Test_findfile()
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/', -1)
|
||||
call assert_equal(2, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
call assert_match('.*/Xfinddir1/bar', l[1])
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1', -1)
|
||||
call assert_equal(2, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
call assert_match('.*/Xfinddir1/bar', l[1])
|
||||
|
||||
" Test combined downwards and upwards search from Xdir2/.
|
||||
cd ../..
|
||||
|
Reference in New Issue
Block a user