aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c19
-rw-r--r--src/nvim/testdir/test_fnamemodify.vim2
2 files changed, 13 insertions, 8 deletions
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')