patch 9.1.0567: Cannot use relative paths as findfile() stop directories

Commit: 
https://github.com/vim/vim/commit/764526e2799fbed040fc867858ee2eb0677afe98
Author: zeertzjq <zeert...@outlook.com>
Date:   Thu Jul 11 22:24:15 2024 +0200

    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: #15200
    closes: #15202
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/findfile.c b/src/findfile.c
index 149f7c685..d1cd5f061 100644
--- a/src/findfile.c
+++ b/src/findfile.c
@@ -418,6 +418,7 @@ vim_findfile_init(
            {
                char_u  *helper;
                void    *ptr;
+               size_t  len;
 
                helper = walker;
                ptr = vim_realloc(search_ctx->ffsc_stopdirs_v,
@@ -428,18 +429,21 @@ vim_findfile_init(
                    // ignore, keep what we have and continue
                    break;
                walker = vim_strchr(walker, ';');
-               if (walker)
+               len = walker ? (size_t)(walker - helper) : STRLEN(helper);
+               // "" means ascent till top of directory tree.
+               if (*helper != NUL && !vim_isAbsName(helper)
+                                                        && len + 1 < MAXPATHL)
                {
+                   // Make the stop dir an absolute path name.
+                   vim_strncpy(ff_expand_buffer, helper, len);
                    search_ctx->ffsc_stopdirs_v[dircount-1] =
-                                        vim_strnsave(helper, walker - helper);
-                   walker++;
+                                       FullName_save(ff_expand_buffer, FALSE);
                }
                else
-                   // this might be "", which means ascent till top
-                   // of directory tree.
                    search_ctx->ffsc_stopdirs_v[dircount-1] =
-                                                         vim_strsave(helper);
-
+                                                    vim_strnsave(helper, len);
+               if (walker)
+                   walker++;
                dircount++;
 
            } while (walker != NULL);
diff --git a/src/testdir/test_findfile.vim b/src/testdir/test_findfile.vim
index 89e583afa..9247a813d 100644
--- a/src/testdir/test_findfile.vim
+++ b/src/testdir/test_findfile.vim
@@ -98,12 +98,25 @@ func Test_findfile()
 
   " Test upwards search with stop-directory.
   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)
   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', ';../../', -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))
@@ -113,6 +126,10 @@ func Test_findfile()
   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', ';../../../', -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 ../..
diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim
index 136acb3dc..8e0797252 100644
--- a/src/testdir/test_taglist.vim
+++ b/src/testdir/test_taglist.vim
@@ -146,6 +146,15 @@ func Test_tagfiles_stopdir()
   let &tags = './Xtags;' .. fnamemodify('./..', ':p')
   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&
   call chdir(save_cwd)
 endfunc
diff --git a/src/version.c b/src/version.c
index 4e14bf18f..c7499bb3f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    567,
 /**/
     566,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sS0R7-000RQh-SG%40256bit.org.

Raspunde prin e-mail lui