changeset 35651:2717d53498e8 v9.1.0567

patch 9.1.0567: Cannot use relative paths as findfile() stop directories Commit: https://github.com/vim/vim/commit/764526e2799fbed040fc867858ee2eb0677afe98 Author: zeertzjq <zeertzjq@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 <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 11 Jul 2024 22:30:41 +0200
parents 96d071ff7c29
children 05181d9232f6
files src/findfile.c src/testdir/test_findfile.vim src/testdir/test_taglist.vim src/version.c
diffstat 4 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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 ../..
--- 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
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    567,
+/**/
     566,
 /**/
     565,