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:
Jaehwang Jung
2026-09-01 10:04:57 +09:00
committed by GitHub
parent 9d2a31b05e
commit ca992e82d4
2 changed files with 13 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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