changeset 20780:300fbeef8c82 v8.2.0942

patch 8.2.0942: expanding to local dir after homedir keeps "~/" Commit: https://github.com/vim/vim/commit/0e390f40e944036fb558a63b91238cfda128d95f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 10 13:12:28 2020 +0200 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 https://github.com/vim/vim/issues/6205, closes #5979)
author Bram Moolenaar <Bram@vim.org>
date Wed, 10 Jun 2020 13:15:03 +0200
parents 0eb9578c85b1
children 93e66f657101
files src/filepath.c src/testdir/test_fnamemodify.vim src/version.c
diffstat 3 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -416,7 +416,7 @@ repeat:
 	// 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 = FullName_save(*fnamep, FALSE);
@@ -2397,11 +2397,9 @@ home_replace(
 		if (--dstlen > 0)
 		    *dst++ = '~';
 
-		/*
-		 * If it's just the home directory, add  "/".
-		 */
-		if (!vim_ispathsep(src[0]) && --dstlen > 0)
-		    *dst++ = '/';
+		// 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)
--- a/src/testdir/test_fnamemodify.vim
+++ b/src/testdir/test_fnamemodify.vim
@@ -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/')
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    942,
+/**/
     941,
 /**/
     940,