]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0367: runtime(netrw): ~ note expanded on MS Windows v9.2.0367
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Sun, 19 Apr 2026 20:38:35 +0000 (20:38 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 19 Apr 2026 20:40:58 +0000 (20:40 +0000)
Problem:  runtime(netrw): ~ note expanded on MS Windows
          (Tom Vamvanij)
Solution: Expand ~ on MS Windows (Yasuhiro Matsumoto)

On Windows, ":Explore ~" did nothing because the tilde expansion was
gated to Unix/Cygwin only.  Additionally, substitute() interprets
backslashes in the replacement string specially (e.g. \U as a case
modifier), which would corrupt $HOME values like C:\Users\name even
if the branch were taken.

Include has("win32") in the guard, anchor the pattern to the start of
the string, and escape backslashes, ampersands and tildes in $HOME
before substituting.

fixes:  #20003
closes: #20014

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/pack/dist/opt/netrw/autoload/netrw.vim
src/testdir/test_plugin_netrw.vim
src/version.c

index 0e6fe6cea612da11db99423ba3131436dce3effc..e3028cb28e2ebaab67f5f5b5fdf8d40034d01223 100644 (file)
@@ -25,6 +25,7 @@
 " 2026 Apr 01 by Vim Project use fnameescape() with netrw#FileUrlEdit()
 " 2026 Apr 05 by Vim Project Fix netrw#RFC2396() #19913
 " 2026 Apr 15 by Vim Project Add missing escape()
+" 2026 Apr 19 by Vim Project expand ~ on Windows #20003
 " Copyright:  Copyright (C) 2016 Charles E. Campbell {{{1
 "             Permission is hereby granted to use and distribute this code,
 "             with or without modifications, provided that this copyright
@@ -530,8 +531,8 @@ function netrw#Explore(indx,dosplit,style,...)
   NetrwKeepj norm! 0
 
   if a:0 > 0
-    if a:1 =~ '^\~' && (has("unix") || g:netrw_cygwin)
-      let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
+    if a:1 =~ '^\~' && (has("unix") || has("win32") || g:netrw_cygwin)
+      let dirname= simplify(substitute(a:1,'^\~',escape(expand("$HOME"),'\&~'),''))
     elseif a:1 == '.'
       let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
       if dirname !~ '/$'
index b23467092815cce0b6a0c011b1beb4fbffd76a92..6ee731d88ffc8ab5aa45caede74d3353205b3053 100644 (file)
@@ -609,4 +609,10 @@ func Test_netrw_RFC2396()
   call assert_equal('a b', netrw#RFC2396(fname))
 endfunc
 
+func Test_netrw_Home_tilde()
+  Explore ~
+  call assert_match('Netrw Directory Listing', getline(2))
+  bw!
+endfunc
+
 " vim:ts=8 sts=2 sw=2 et
index 4c2be4b468010861bb3569dd92177f57c77f0ef0..20e593ac87dec8f9c0066768f623a2e65afcc7c3 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    367,
 /**/
     366,
 /**/