patch 9.1.0569: fnamemodify() treats ".." and "../" differently

Commit: 
https://github.com/vim/vim/commit/1ee7420460768df67ea4bc73467f2d4f8b1555bd
Author: zeertzjq <zeert...@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 <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/os_unix.c b/src/os_unix.c
index 474d28801..76e7a8a02 100644
--- 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
diff --git a/src/testdir/test_findfile.vim b/src/testdir/test_findfile.vim
index 9247a813d..a5e18b957 100644
--- 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 ../..
diff --git a/src/testdir/test_fnamemodify.vim b/src/testdir/test_fnamemodify.vim
index c19f4646b..4e61343fa 100644
--- 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', ':~'))
diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim
index 8e0797252..236f5ac07 100644
--- 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
diff --git a/src/version.c b/src/version.c
index 3b4cca66d..4c6ed9960 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 */
+/**/
+    569,
 /**/
     568,
 /**/

-- 
-- 
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/E1sS95g-001H5k-S3%40256bit.org.

Raspunde prin e-mail lui