mirror of
https://github.com/neovim/neovim.git
synced 2026-09-03 04:43:48 +00:00
fix(buffer): keep trailing slash significant in URI names #41577
Problem: Literal path comparison ignored one trailing slash for every buffer name, including URIs. Generic URI syntax does not make a non-empty path equivalent to the same path with a trailing slash, so distinct URI buffers collapsed into one. Solution: Require equal lengths when comparing URI buffer names, while retaining trailing-separator normalization for filesystem paths. AI-assisted
This commit is contained in:
@@ -64,7 +64,10 @@ bool path_equal(const char *s1, const char *s2, PathCmpFlags flags)
|
||||
assert(!(flags & kPathCmpLiteral) || flags == kPathCmpLiteral);
|
||||
|
||||
if (flags == kPathCmpLiteral) {
|
||||
return path_cmp(p_fic, s1, s2, MAXPATHL) == 0;
|
||||
const bool is_url = path_with_url(s1) || path_with_url(s2);
|
||||
// URI comparison is scheme-agnostic, so a trailing slash is significant.
|
||||
return (!is_url || strlen(s1) == strlen(s2))
|
||||
&& path_cmp(p_fic, s1, s2, MAXPATHL) == 0;
|
||||
}
|
||||
|
||||
if (flags & kPathCmpExpand) {
|
||||
|
||||
@@ -2420,6 +2420,15 @@ describe('api/buf', function()
|
||||
eq(cwd .. '/' .. link .. '/', t.fix_slashes(api.nvim_buf_get_name(0)))
|
||||
end)
|
||||
|
||||
it('allows URI buffer names that differ by a trailing slash', function()
|
||||
api.nvim_buf_set_name(0, 'test://example')
|
||||
local trailing_slash = api.nvim_create_buf(true, false)
|
||||
api.nvim_buf_set_name(trailing_slash, 'test://example/')
|
||||
|
||||
eq('test://example', api.nvim_buf_get_name(0))
|
||||
eq('test://example/', api.nvim_buf_get_name(trailing_slash))
|
||||
end)
|
||||
|
||||
describe("with 'autochdir'", function()
|
||||
local topdir
|
||||
local oldbuf
|
||||
|
||||
Reference in New Issue
Block a user