]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0569: fnamemodify() treats ".." and "../" differently v9.1.0569
authorzeertzjq <zeertzjq@outlook.com>
Fri, 12 Jul 2024 05:29:14 +0000 (07:29 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 12 Jul 2024 05:29:14 +0000 (07:29 +0200)
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>
src/os_unix.c
src/testdir/test_findfile.vim
src/testdir/test_fnamemodify.vim
src/testdir/test_taglist.vim
src/version.c

index 474d28801977279b53d33593bcd3bdd233d031be..76e7a8a0270d4f68da3d159a2fe3cbb8d5cf2c7e 100644 (file)
@@ -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
index 9247a813daa40a9c2a0cec02e23d893d0635aeb6..a5e18b9570619adb6baaaa0b0ea36c6ba739d495 100644 (file)
@@ -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 ../..
index c19f4646b37f017904c1433ec595dac57c4f390d..4e61343fa47cb5318d99f415d028b0a44af53450 100644 (file)
@@ -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', ':~'))
index 8e0797252a153a263dda8f87e6db2338da8216a0..236f5ac0717d80c1ac5045adf3757e1d2ad1012d 100644 (file)
@@ -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
index 3b4cca66d413f69307a12825ad0981501cdb3c9d..4c6ed9960a28adc157f553e5ced2c81a24803912 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    569,
 /**/
     568,
 /**/