Merge pull request #29698 from neovim/backport-29667-to-release-0.10

vim-patch:8.2.3388: fnamemodify('path/..', ':p') differs from using 'path/../'
This commit is contained in:
zeertzjq
2024-07-14 14:12:30 +08:00
committed by GitHub
2 changed files with 7 additions and 1 deletions

View File

@@ -2385,10 +2385,14 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force)
}
#endif
if (p != NULL) {
if (strcmp(p + 1, "..") == 0) {
// for "/path/dir/.." include the "/.."
p += 3;
}
assert(p >= fname);
memcpy(relative_directory, fname, (size_t)(p - fname + 1));
relative_directory[p - fname + 1] = NUL;
end_of_path = p + 1;
end_of_path = (vim_ispathsep_nocolon(*p) ? p + 1 : p);
} else {
relative_directory[0] = NUL;
}

View 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', ':~'))