changeset 35656:c2f74389a856 v9.1.0569

patch 9.1.0569: fnamemodify() treats ".." and "../" differently Commit: https://github.com/vim/vim/commit/1ee7420460768df67ea4bc73467f2d4f8b1555bd Author: zeertzjq <zeertzjq@outlook.com> Date: Fri Jul 12 07:29:14 2024 +0200 patch 9.1.0569: fnamemodify() treats ".." and "../" differently Problem: fnamemodify() treats ".." and "../" differently. Solution: Expand ".." properly like how "/.." is treated in 8.2.3388. (zeertzjq) closes: #15218 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Fri, 12 Jul 2024 07:45:07 +0200
parents bf08e2efcba1
children b7d6523899eb
files src/os_unix.c src/testdir/test_findfile.vim src/testdir/test_fnamemodify.vim src/testdir/test_taglist.vim src/version.c
diffstat 5 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -2699,6 +2699,9 @@ mch_FullName(
     if ((force || !mch_isFullName(fname))
 	    && ((p = vim_strrchr(fname, '/')) == NULL || p != fname))
     {
+	if (p == NULL && STRCMP(fname, "..") == 0)
+	    // Handle ".." without path separators.
+	    p = fname + 2;
 	/*
 	 * If the file name has a path, change to that directory for a moment,
 	 * and then get the directory (and get back to where we were).
@@ -2707,7 +2710,7 @@ mch_FullName(
 	if (p != NULL)
 	{
 	    if (STRCMP(p, "/..") == 0)
-		// for "/path/dir/.." include the "/.."
+		// For "/path/dir/.." include the "/..".
 		p += 3;
 
 #ifdef HAVE_FCHDIR
--- a/src/testdir/test_findfile.vim
+++ b/src/testdir/test_findfile.vim
@@ -107,6 +107,9 @@ func Test_findfile()
   let l = findfile('bar', ';../', -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))
@@ -117,6 +120,9 @@ func Test_findfile()
   let l = findfile('bar', ';../../', -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))
@@ -130,6 +136,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_fnamemodify.vim
+++ b/src/testdir/test_fnamemodify.vim
@@ -14,6 +14,8 @@ func Test_fnamemodify()
   call assert_equal($HOME .. "/foo" , fnamemodify('~/foo', ':p'))
   call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/../', ':p'))
   call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/..', ':p'))
+  call assert_equal(fnamemodify('.', ':p:h:h') .. '/', fnamemodify('../', ':p'))
+  call assert_equal(fnamemodify('.', ':p:h:h') .. '/', fnamemodify('..', ':p'))
   call assert_equal('test.out', fnamemodify('test.out', ':.'))
   call assert_equal('a', fnamemodify('../testdir/a', ':.'))
   call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))
--- a/src/testdir/test_taglist.vim
+++ b/src/testdir/test_taglist.vim
@@ -135,15 +135,15 @@ func Test_tagfiles_stopdir()
   call writefile([], 'Xtagsdir1/Xtags', 'D')
 
   cd Xtagsdir1/
-  let &tags = './Xtags;' .. fnamemodify('./..', ':p')
+  let &tags = './Xtags;' .. fnamemodify('..', ':p')
   call assert_equal(1, len(tagfiles()))
 
   cd Xtagsdir2/
-  let &tags = './Xtags;' .. fnamemodify('./..', ':p')
+  let &tags = './Xtags;' .. fnamemodify('..', ':p')
   call assert_equal(1, len(tagfiles()))
 
   cd Xtagsdir3/
-  let &tags = './Xtags;' .. fnamemodify('./..', ':p')
+  let &tags = './Xtags;' .. fnamemodify('..', ':p')
   call assert_equal(0, len(tagfiles()))
 
   let &tags = './Xtags;../'
@@ -155,6 +155,15 @@ func Test_tagfiles_stopdir()
   cd ..
   call assert_equal(1, len(tagfiles()))
 
+  let &tags = './Xtags;..'
+  call assert_equal(1, len(tagfiles()))
+
+  cd Xtagsdir2/
+  call assert_equal(1, len(tagfiles()))
+
+  cd Xtagsdir3/
+  call assert_equal(0, 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 */
 /**/
+    569,
+/**/
     568,
 /**/
     567,