]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3219: :find searches non-existing directories v8.2.3219
authorChristian Brabandt <cb@256bit.org>
Sun, 25 Jul 2021 13:08:05 +0000 (15:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 25 Jul 2021 13:08:05 +0000 (15:08 +0200)
Problem:    :find searches non-existing directories.
Solution:   Check the path is not "..".  Update help. (Christian Brabandt,
            closes #8612, closes #8533)

runtime/doc/editing.txt
src/findfile.c
src/testdir/test_findfile.vim
src/version.c

index 23317986892e6320ce9b643fc7ccd0fdfef09df3..6bc245abcb253bbbabda7c51f07dd48780f37b84 100644 (file)
@@ -1749,6 +1749,12 @@ There are three different types of searching:
        /u/user_x/work/include
        /u/user_x/include
 
+<   Note: If your 'path' setting includes an non-existing directory, Vim will
+   skip the non-existing directory, but continues searching in the parent of
+   the non-existing directory if upwards searching is used.  E.g. when
+   searching "../include" and that doesn't exist, and upward searching is
+   used, also searches in "..".
+
 3) Combined up/downward search:
    If Vim's current path is /u/user_x/work/release and you do >
        set path=**;/u/user_x
index a72fe45ad9c903c3a3922830ede475e00e1334c9..7c2a61f4ae230a27ddedd854b0a4fc2822807721 100644 (file)
@@ -578,7 +578,16 @@ vim_findfile_init(
 
            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;
+               if ((len >= 2
+                       && STRNCMP(search_ctx->ffsc_fix_path, "..", 2) == 0)
+                       && (len == 2
+                                  || search_ctx->ffsc_fix_path[2] == PATHSEP))
+               {
+                   vim_free(buf);
+                   goto error_return;
+               }
                STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len);
                add_pathsep(ff_expand_buffer);
            }
index 188851feef70c401cabf4ad0873ade03441617a0..017089eac4bad767b6281df2d7d6aa6d6b83f593 100644 (file)
@@ -228,4 +228,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
index 9b334e67496338b0971a7cbaf1f5acceeacc4270..ac5989f6f5dc260ec588825f9e331a8b7de8dcc7 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3219,
 /**/
     3218,
 /**/