mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(path): don't remove trailing slash when getting absolute path (#20853)
Before Vim patch 8.2.3468 relative_directory is never used in the resulting path name, so whether it has a trailing slash didn't matter. Now path_full_dir_name() appends a non-existing relative directory to the current directory name, so the trailing slash needs to be kept.
This commit is contained in:
@@ -2362,16 +2362,9 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
// relative to root
|
|
||||||
if (p == fname) {
|
|
||||||
// only one path component
|
|
||||||
relative_directory[0] = PATHSEP;
|
|
||||||
relative_directory[1] = NUL;
|
|
||||||
} else {
|
|
||||||
assert(p >= fname);
|
assert(p >= fname);
|
||||||
memcpy(relative_directory, fname, (size_t)(p - fname));
|
memcpy(relative_directory, fname, (size_t)(p - fname + 1));
|
||||||
relative_directory[p - fname] = NUL;
|
relative_directory[p - fname + 1] = NUL;
|
||||||
}
|
|
||||||
end_of_path = p + 1;
|
end_of_path = p + 1;
|
||||||
} else {
|
} else {
|
||||||
relative_directory[0] = NUL;
|
relative_directory[0] = NUL;
|
||||||
|
@@ -504,6 +504,16 @@ describe('path.c', function()
|
|||||||
eq(OK, result)
|
eq(OK, result)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
itp('does not remove trailing slash from non-existing relative directory #20847', function()
|
||||||
|
local expected = lfs.currentdir() .. '/non_existing_dir/'
|
||||||
|
local filename = 'non_existing_dir/'
|
||||||
|
local buflen = get_buf_len(expected, filename)
|
||||||
|
local do_expand = 1
|
||||||
|
local buf, result = vim_FullName(filename, buflen, do_expand)
|
||||||
|
eq(expected, ffi.string(buf))
|
||||||
|
eq(OK, result)
|
||||||
|
end)
|
||||||
|
|
||||||
itp('expands "./" to the current directory #7117', function()
|
itp('expands "./" to the current directory #7117', function()
|
||||||
local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
|
local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
|
||||||
local filename = './unit-test-directory/test.file'
|
local filename = './unit-test-directory/test.file'
|
||||||
|
Reference in New Issue
Block a user