From ca992e82d40cb8ed31331ba75cf0a58c6d693ac7 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Tue, 1 Sep 2026 10:04:57 +0900 Subject: [PATCH] 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 --- src/nvim/path.c | 5 ++++- test/functional/api/buffer_spec.lua | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nvim/path.c b/src/nvim/path.c index d9009a0909..bce5b6f510 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -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) { diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index d46a704773..551bc4091f 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -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