Mercurial > vim
changeset 25705:f165d99cda45 v8.2.3388
patch 8.2.3388: fnamemodify('path/..', ':p') differs from using 'path/../'
Commit: https://github.com/vim/vim/commit/4eaef9979fc5032606897963f1af37674ee0d422
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Aug 30 21:26:16 2021 +0200
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 https://github.com/vim/vim/issues/8808)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 30 Aug 2021 21:30:04 +0200 |
parents | 168dc6cad230 |
children | db2130b7a83f |
files | src/os_unix.c src/testdir/test_fnamemodify.vim src/version.c |
diffstat | 3 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/os_unix.c +++ b/src/os_unix.c @@ -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 if (*p == '/') + fname = p + 1; else - fname = p + 1; + fname = p; *buf = NUL; } }
--- a/src/testdir/test_fnamemodify.vim +++ b/src/testdir/test_fnamemodify.vim @@ -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', ':~'))