]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0676: MS-Windows: cannot switch to a buffer with '%' in its name v9.2.0676
authorHirohito Higashi <h.east.727@gmail.com>
Thu, 18 Jun 2026 19:31:18 +0000 (19:31 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 18 Jun 2026 19:31:18 +0000 (19:31 +0000)
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) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_buffer.vim
src/version.c
src/vim.h

index 4f0f1acb24f4c2365fc791cf07b812705497a80d..733ef6543492aa473b68866dd759daa00d9728ca 100644 (file)
@@ -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
index 14ebcf34336d547611c7aad0f0896f685cbdcd2a..5aa9fde1c1e77f97d4a8f4d4243b6319e3f3967f 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    676,
 /**/
     675,
 /**/
index 640afc62edbc5eb1365a7b78037beea7ad35a61b..0e1cc1d27abca863fc3e539d9502dfd8f0b11f17 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
 #endif
 #ifdef BACKSLASH_IN_FILENAME
 # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<")
-# define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`%#'\"|!<")
+// '%' 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 *)" \t\n*?[`'\"|!<")
 #else
 # ifdef VMS
     // VMS allows a lot of characters in the file name