patch 9.2.0676: MS-Windows: cannot switch to a buffer with '%' in its name

Commit: 
https://github.com/vim/vim/commit/1a96e07bf6ba46f4b6f50a861d755d0fbc89dabb
Author: Hirohito Higashi <[email protected]>
Date:   Thu Jun 18 19:31:18 2026 +0000

    patch 9.2.0676: MS-Windows: cannot switch to a buffer with '%' in its name
    
    Problem:  On MS-Windows it is not possible to switch to a buffer by name
              with ":b" (including via command-line completion) when the
              buffer name contains '%'.
    Solution: Do not escape '%' and '#' for the ":buffer" command on
              MS-Windows.  Since ":buffer" has no EX_XFILE these are not
              expanded, and escaping them as "\%"/"\#" makes buffer name
              matching fail when '%'/'#' is in 'isfname' (the backslash is
              treated as a path separator).
    
    fixes:  #20529
    closes: #20548
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index 4f0f1acb2..733ef6543 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -935,4 +935,19 @@ func Test_split_window_in_BufLeave_from_switching_buffer()
   bwipe! Xb
 endfunc
 
+" Switch to a buffer whose name contains '%' via completion (#20529).
+func Test_buffer_switch_to_name_with_percent()
+  CheckMSWindows
+
+  let bufnr = bufadd('Xpercent%name')
+  call setbufvar(bufnr, '&buflisted', 1)
+  call bufload(bufnr)
+  enew
+
+  call feedkeys(":b Xpercent\<Tab>\<CR>", 'xt')
+  call assert_equal(bufnr, bufnr('%'))
+
+  exe 'bwipe! ' .. bufnr
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 14ebcf343..5aa9fde1c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    676,
 /**/
     675,
 /**/
diff --git a/src/vim.h b/src/vim.h
index 640afc62e..0e1cc1d27 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -343,7 +343,10 @@
 #endif
 #ifdef BACKSLASH_IN_FILENAME
 # define PATH_ESC_CHARS ((char_u *)"   
*?[{`%#'\"|!<")
-# define BUFFER_ESC_CHARS ((char_u *)"         
*?[`%#'\"|!<")
+// '%' and '#' are not escaped for ":buffer": it has no EX_XFILE, so they are
+// not expanded, and escaping them as "\%"/"\#" breaks buffer name matching
+// when '%'/'#' is in 'isfname' (backslash treated as a path separator).
+# define BUFFER_ESC_CHARS ((char_u *)"         
*?[`'\"|!<")
 #else
 # ifdef VMS
     // VMS allows a lot of characters in the file name

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1waIfg-004Rg7-QH%40256bit.org.

Raspunde prin e-mail lui