]> granicus.if.org Git - vim/commitdiff
patch 8.2.3388: fnamemodify('path/..', ':p') differs from using 'path/../' v8.2.3388
authorBram Moolenaar <Bram@vim.org>
Mon, 30 Aug 2021 19:26:16 +0000 (21:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 30 Aug 2021 19:26:16 +0000 (21:26 +0200)
Problem:    fnamemodify('path/..', ':p') differs from using 'path/../'.
Solution:   Include the "/.." in the directory name. (closes #8808)

src/os_unix.c
src/testdir/test_fnamemodify.vim
src/version.c

index b603927e3679e2df77e8bac272f3b9fa3494b7cf..a3e5430ef915b5da1d09036c6b98a7e38b8c6a31 100644 (file)
@@ -2602,6 +2602,10 @@ mch_FullName(
         */
        if (p != NULL)
        {
+           if (STRCMP(p, "/..") == 0)
+               // for "/path/dir/.." include the "/.."
+               p += 3;
+
 #ifdef HAVE_FCHDIR
            /*
             * Use fchdir() if possible, it's said to be faster and more
@@ -2644,8 +2648,10 @@ mch_FullName(
                    vim_strncpy(buf, fname, p - fname);
                    if (mch_chdir((char *)buf))
                        retval = FAIL;
-                   else
+                   else if (*p == '/')
                        fname = p + 1;
+                   else
+                       fname = p;
                    *buf = NUL;
                }
            }
index bcbdf77ae491a9d7cedd80ac0fbe47aefd083c32..7882f3cb0dbcf5f62f5606db219b4beac6593e0a 100644 (file)
@@ -12,6 +12,8 @@ func Test_fnamemodify()
   call assert_equal('r', fnamemodify('.', ':p:h')[-1:])
   call assert_equal('t', fnamemodify('test.out', ':p')[-1:])
   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('test.out', fnamemodify('test.out', ':.'))
   call assert_equal('a', fnamemodify('../testdir/a', ':.'))
   call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))
index af45dedfff88ac8f043d36ea703e530d58590bef..7aef272f62847a49ae1559e4bef6b9e76789acd1 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3388,
 /**/
     3387,
 /**/