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