Skip to content

Commit 4eaef99

Browse files
committed
patch 8.2.3388: fnamemodify('path/..', ':p') differs from using 'path/../'
Problem: fnamemodify('path/..', ':p') differs from using 'path/../'. Solution: Include the "/.." in the directory name. (closes #8808)
1 parent de05ae7 commit 4eaef99

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/os_unix.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,10 @@ mch_FullName(
26022602
*/
26032603
if (p != NULL)
26042604
{
2605+
if (STRCMP(p, "/..") == 0)
2606+
// for "/path/dir/.." include the "/.."
2607+
p += 3;
2608+
26052609
#ifdef HAVE_FCHDIR
26062610
/*
26072611
* Use fchdir() if possible, it's said to be faster and more
@@ -2644,8 +2648,10 @@ mch_FullName(
26442648
vim_strncpy(buf, fname, p - fname);
26452649
if (mch_chdir((char *)buf))
26462650
retval = FAIL;
2647-
else
2651+
else if (*p == '/')
26482652
fname = p + 1;
2653+
else
2654+
fname = p;
26492655
*buf = NUL;
26502656
}
26512657
}

src/testdir/test_fnamemodify.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func Test_fnamemodify()
1212
call assert_equal('r', fnamemodify('.', ':p:h')[-1:])
1313
call assert_equal('t', fnamemodify('test.out', ':p')[-1:])
1414
call assert_equal($HOME .. "/foo" , fnamemodify('~/foo', ':p'))
15+
call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/../', ':p'))
16+
call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/..', ':p'))
1517
call assert_equal('test.out', fnamemodify('test.out', ':.'))
1618
call assert_equal('a', fnamemodify('../testdir/a', ':.'))
1719
call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3388,
758760
/**/
759761
3387,
760762
/**/

0 commit comments

Comments
 (0)