vim-patch:8.2.0942: expanding to local dir after homedir keeps "~/"

Problem:    Expanding to local dir after homedir keeps "~/".
Solution:   Adjust modify_fname(). (Christian Brabandt, closes vim/vim#6205,
            closes vim/vim#5979)
0e390f40e9
This commit is contained in:
zeertzjq 2022-02-07 06:48:10 +08:00
parent f47ba10636
commit 53e4434c72
3 changed files with 7 additions and 5 deletions

View File

@ -10700,7 +10700,7 @@ repeat:
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
if (!has_fullname && !has_homerelative) {
if (c == '.' && **fnamep == '~') {
if ((c == '.' || c == '~') && **fnamep == '~') {
p = pbuf = expand_env_save(*fnamep);
} else {
p = pbuf = (char_u *)FullName_save((char *)*fnamep, FALSE);

View File

@ -1111,10 +1111,9 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char_u *const dst
*dst_p++ = '~';
}
// If it's just the home directory, add "/".
if (!vim_ispathsep(src[0]) && --dstlen > 0) {
*dst_p++ = '/';
}
// Do not add directory separator into dst, because dst is
// expected to just return the directory name without the
// directory separator '/'.
break;
}
if (p == homedir_env_mod) {

View File

@ -31,6 +31,9 @@ func Test_fnamemodify()
call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r'))
let cwd = getcwd()
call chdir($HOME)
call assert_equal('foobar', fnamemodify('~/foobar', ':~:.'))
call chdir(cwd)
call mkdir($HOME . '/XXXXXXXX/a', 'p')
call mkdir($HOME . '/XXXXXXXX/b', 'p')
call chdir($HOME . '/XXXXXXXX/a/')