diff --git a/src/nvim/path.c b/src/nvim/path.c index 9d4c8d7bde..f09535cdb5 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2121,7 +2121,10 @@ char *path_shorten_fname(char *full_path, char *dir_name) return NULL; } - return p + 1; + do { + p++; + } while (vim_ispathsep_nocolon(*p)); + return p; } /// Invoke expand_wildcards() for one pattern diff --git a/test/old/testdir/test_cd.vim b/test/old/testdir/test_cd.vim index 03f114cf41..ca3ad12344 100644 --- a/test/old/testdir/test_cd.vim +++ b/test/old/testdir/test_cd.vim @@ -414,4 +414,15 @@ func Test_cd_symlinks() call chdir(savedir) endfunc +func Test_cd_shorten_bufname_with_duplicate_slashes() + let savedir = getcwd() + call mkdir('Xexistingdir', 'R') + new Xexistingdir//foo/bar + cd Xexistingdir + call assert_equal('foo/bar', bufname('%')) + + call chdir(savedir) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 8aa2121f34..21f0556aed 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -299,6 +299,11 @@ describe('path.c', function() local full = to_cstr('some/very/long/directory/file.txt') local dir = to_cstr('some/very/long') eq('directory/file.txt', (ffi.string(cimp.path_shorten_fname(full, dir)))) + -- Also works with duplicate slashes. #37080 + full = to_cstr('some/very/long//directory/file.txt') + eq('directory/file.txt', (ffi.string(cimp.path_shorten_fname(full, dir)))) + full = to_cstr('some/very/long///directory/file.txt') + eq('directory/file.txt', (ffi.string(cimp.path_shorten_fname(full, dir)))) end) end) end)