diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-01-30 14:53:56 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-02-01 17:08:40 +0800 |
commit | 7d72076a6f3bd3cb85100c94bfeb7a70de345c3b (patch) | |
tree | 8b6f22f2fa203841f910ea38745e4c36ad77af9f /src | |
parent | a562b5771ea91becd0a469378ec852feaf50d2d0 (diff) | |
download | rneovim-7d72076a6f3bd3cb85100c94bfeb7a70de345c3b.tar.gz rneovim-7d72076a6f3bd3cb85100c94bfeb7a70de345c3b.tar.bz2 rneovim-7d72076a6f3bd3cb85100c94bfeb7a70de345c3b.zip |
vim-patch:8.2.3219: :find searches non-existing directories
Problem: :find searches non-existing directories.
Solution: Check the path is not "..". Update help. (Christian Brabandt,
closes vim/vim#8612, closes vim/vim#8533)
https://github.com/vim/vim/commit/7a4ca32175bef0f9a177052796bd9addd10dc218
Change STRNCAT to STRLCAT as clint doesn't like the former.
Include a typo fix from https://github.com/vim/vim/commit/2f0936cb9a2eb026acac03e6a8fd0b2a5d97508b#diff-7e9292cae1f2ba70dd5b17d2d162693a91044ada6ac99e9c3e8917f32878c097
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/file_search.c | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_findfile.vim | 22 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index b4becb3066..25dbf680de 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -483,8 +483,14 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le int len = 0; if (p > search_ctx->ffsc_fix_path) { + // do not add '..' to the path and start upwards searching len = (int)(p - search_ctx->ffsc_fix_path) - 1; - STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len); + if ((len >= 2 && STRNCMP(search_ctx->ffsc_fix_path, "..", 2) == 0) + && (len == 2 || search_ctx->ffsc_fix_path[2] == PATHSEP)) { + xfree(buf); + goto error_return; + } + STRLCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, eb_len + (size_t)len + 1); add_pathsep((char *)ff_expand_buffer); } else { len = (int)STRLEN(search_ctx->ffsc_fix_path); diff --git a/src/nvim/testdir/test_findfile.vim b/src/nvim/testdir/test_findfile.vim index 5a20475d3d..1684c5d30a 100644 --- a/src/nvim/testdir/test_findfile.vim +++ b/src/nvim/testdir/test_findfile.vim @@ -226,4 +226,26 @@ func Test_find_cmd() call assert_fails('tabfind', 'E471:') endfunc +func Test_find_non_existing_path() + new + let save_path = &path + let save_dir = getcwd() + call mkdir('dir1/dir2', 'p') + call writefile([], 'dir1/file.txt') + call writefile([], 'dir1/dir2/base.txt') + call chdir('dir1/dir2') + e base.txt + set path=../include + + call assert_fails(':find file.txt', 'E345:') + + call chdir(save_dir) + bw! + call delete('dir1/dir2/base.txt', 'rf') + call delete('dir1/dir2', 'rf') + call delete('dir1/file.txt', 'rf') + call delete('dir1', 'rf') + let &path = save_path +endfunc + " vim: shiftwidth=2 sts=2 expandtab |