From f47ba10636b498430fc8d2d490e5bdf6b4e01033 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Feb 2022 06:48:10 +0800 Subject: vim-patch:8.2.0215: wrong file name shortening Problem: Wrong file name shortening. (Ingo Karkat) Solution: Better check for path separator. (Yasuhiro Matsumoto, closes vim/vim#5583, closes vim/vim#5584) https://github.com/vim/vim/commit/a78e9c61a0ded9c5302bc77e889aa1b3d3467f61 --- src/nvim/eval.c | 19 +++++++++++-------- src/nvim/testdir/test_fnamemodify.vim | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 70909b46cb..0fe928beb7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10725,14 +10725,17 @@ repeat: // even though the path does not have a prefix. if (fnamencmp(p, dirname, namelen) == 0) { p += namelen; - while (*p && vim_ispathsep(*p)) { - ++p; - } - *fnamep = p; - if (pbuf != NULL) { - xfree(*bufp); // free any allocated file name - *bufp = pbuf; - pbuf = NULL; + if (vim_ispathsep(*p)) { + while (*p && vim_ispathsep(*p)) { + p++; + } + *fnamep = p; + if (pbuf != NULL) { + // free any allocated file name + xfree(*bufp); + *bufp = pbuf; + pbuf = NULL; + } } } } else { diff --git a/src/nvim/testdir/test_fnamemodify.vim b/src/nvim/testdir/test_fnamemodify.vim index e8fad397c3..ca17be41ec 100644 --- a/src/nvim/testdir/test_fnamemodify.vim +++ b/src/nvim/testdir/test_fnamemodify.vim @@ -36,6 +36,8 @@ func Test_fnamemodify() call chdir($HOME . '/XXXXXXXX/a/') call assert_equal('foo', fnamemodify($HOME . '/XXXXXXXX/a/foo', ':p:~:.')) call assert_equal('~/XXXXXXXX/b/foo', fnamemodify($HOME . '/XXXXXXXX/b/foo', ':p:~:.')) + call mkdir($HOME . '/XXXXXXXX/a.ext', 'p') + call assert_equal('~/XXXXXXXX/a.ext/foo', fnamemodify($HOME . '/XXXXXXXX/a.ext/foo', ':p:~:.')) call chdir(cwd) call delete($HOME . '/XXXXXXXX', 'rf') -- cgit