mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-patch:9.1.0567: Cannot use relative paths as findfile() stop directories
Problem: Cannot use relative paths as findfile() stop directories. Solution: Change a relative path to an absolute path. (zeertzjq) related: vim/vim#15200 closes: vim/vim#15202764526e279
(cherry picked from commit80818641f3
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
c467bfeb93
commit
576363a0fb
@@ -349,23 +349,24 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
|
|||||||
search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char *));
|
search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char *));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char *helper;
|
char *helper = walker;
|
||||||
void *ptr;
|
void *ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
|
||||||
|
|
||||||
helper = walker;
|
|
||||||
ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
|
|
||||||
(dircount + 1) * sizeof(char *));
|
(dircount + 1) * sizeof(char *));
|
||||||
search_ctx->ffsc_stopdirs_v = ptr;
|
search_ctx->ffsc_stopdirs_v = ptr;
|
||||||
walker = vim_strchr(walker, ';');
|
walker = vim_strchr(walker, ';');
|
||||||
if (walker) {
|
assert(!walker || walker - helper >= 0);
|
||||||
assert(walker - helper >= 0);
|
size_t len = walker ? (size_t)(walker - helper) : strlen(helper);
|
||||||
search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrnsave(helper, (size_t)(walker - helper));
|
// "" means ascent till top of directory tree.
|
||||||
walker++;
|
if (*helper != NUL && !vim_isAbsName(helper) && len + 1 < MAXPATHL) {
|
||||||
|
// Make the stop dir an absolute path name.
|
||||||
|
xmemcpyz(ff_expand_buffer, helper, len);
|
||||||
|
search_ctx->ffsc_stopdirs_v[dircount - 1] = FullName_save(helper, len);
|
||||||
} else {
|
} else {
|
||||||
// this might be "", which means ascent till top of directory tree.
|
search_ctx->ffsc_stopdirs_v[dircount - 1] = xmemdupz(helper, len);
|
||||||
search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrdup(helper);
|
}
|
||||||
|
if (walker) {
|
||||||
|
walker++;
|
||||||
}
|
}
|
||||||
|
|
||||||
dircount++;
|
dircount++;
|
||||||
} while (walker != NULL);
|
} while (walker != NULL);
|
||||||
search_ctx->ffsc_stopdirs_v[dircount - 1] = NULL;
|
search_ctx->ffsc_stopdirs_v[dircount - 1] = NULL;
|
||||||
|
@@ -98,12 +98,25 @@ func Test_findfile()
|
|||||||
|
|
||||||
" Test upwards search with stop-directory.
|
" Test upwards search with stop-directory.
|
||||||
cd Xdir2
|
cd Xdir2
|
||||||
|
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/Xdir3/', -1)
|
||||||
|
call assert_equal(1, len(l))
|
||||||
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
|
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/Xdir3', -1)
|
||||||
|
call assert_equal(1, len(l))
|
||||||
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
|
let l = findfile('bar', ';../', -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)
|
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/', -1)
|
||||||
call assert_equal(1, len(l))
|
call assert_equal(1, len(l))
|
||||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2', -1)
|
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2', -1)
|
||||||
call assert_equal(1, len(l))
|
call assert_equal(1, len(l))
|
||||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
|
let l = findfile('bar', ';../../', -1)
|
||||||
|
call assert_equal(1, len(l))
|
||||||
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
|
|
||||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/', -1)
|
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/', -1)
|
||||||
call assert_equal(2, len(l))
|
call assert_equal(2, len(l))
|
||||||
@@ -113,6 +126,10 @@ func Test_findfile()
|
|||||||
call assert_equal(2, len(l))
|
call assert_equal(2, len(l))
|
||||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||||
call assert_match('.*/Xfinddir1/bar', l[1])
|
call assert_match('.*/Xfinddir1/bar', l[1])
|
||||||
|
let l = findfile('bar', ';../../../', -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/.
|
" Test combined downwards and upwards search from Xdir2/.
|
||||||
cd ../..
|
cd ../..
|
||||||
|
@@ -154,6 +154,15 @@ func Test_tagfiles_stopdir()
|
|||||||
let &tags = './Xtags;' .. fnamemodify('./..', ':p')
|
let &tags = './Xtags;' .. fnamemodify('./..', ':p')
|
||||||
call assert_equal(0, len(tagfiles()))
|
call assert_equal(0, len(tagfiles()))
|
||||||
|
|
||||||
|
let &tags = './Xtags;../'
|
||||||
|
call assert_equal(0, len(tagfiles()))
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
call assert_equal(1, len(tagfiles()))
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
call assert_equal(1, len(tagfiles()))
|
||||||
|
|
||||||
set tags&
|
set tags&
|
||||||
call chdir(save_cwd)
|
call chdir(save_cwd)
|
||||||
endfunc
|
endfunc
|
||||||
|
Reference in New Issue
Block a user