Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(path): don't remove trailing slash when getting absolute path #20853

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/nvim/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -2362,16 +2362,9 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force)
}
#endif
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);
memcpy(relative_directory, fname, (size_t)(p - fname));
relative_directory[p - fname] = NUL;
}
assert(p >= fname);
memcpy(relative_directory, fname, (size_t)(p - fname + 1));
relative_directory[p - fname + 1] = NUL;
end_of_path = p + 1;
} else {
relative_directory[0] = NUL;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/path_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ describe('path.c', function()
eq(OK, result)
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()
local expected = lfs.currentdir() .. '/unit-test-directory/test.file'
local filename = './unit-test-directory/test.file'
Expand Down