]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1135: 'suffixesadd' doesn't work with multiple items v9.1.1135
authorzeertzjq <zeertzjq@outlook.com>
Sat, 22 Feb 2025 08:13:17 +0000 (09:13 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 22 Feb 2025 08:13:17 +0000 (09:13 +0100)
Problem:  'suffixesadd' doesn't work with multiple items
          (after 9.1.1122).
Solution: Don't concat multiple suffixes together.
          (zeertzjq)

fixes: #16694
closes: #16699

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/findfile.c
src/testdir/test_findfile.vim
src/testdir/test_gf.vim
src/version.c

index ccb3ef8853d8c800c893fc5e22cb1894ff40a845..2bd1e7eb997a5febb208025d5bf768f19aade489 100644 (file)
@@ -1082,6 +1082,7 @@ vim_findfile(void *search_ctx_arg)
                         * Try without extra suffix and then with suffixes
                         * from 'suffixesadd'.
                         */
+                       len = file_path.length;
                        if (search_ctx->ffsc_tagfile)
                            suf = (char_u *)"";
                        else
@@ -1164,8 +1165,8 @@ vim_findfile(void *search_ctx_arg)
                            // Not found or found already, try next suffix.
                            if (*suf == NUL)
                                break;
-                           file_path.length += copy_option_part(&suf, file_path.string + file_path.length,
-                                                        MAXPATHL - file_path.length, ",");
+                           file_path.length = len + copy_option_part(&suf,
+                                 file_path.string + len, MAXPATHL - len, ",");
                        }
                    }
                }
@@ -1872,6 +1873,7 @@ find_file_in_path_option(
        if (first == TRUE)
        {
            int         l;
+           int         NameBufflen;
            int         run;
            size_t      rel_fnamelen = 0;
            char_u      *suffix;
@@ -1912,6 +1914,7 @@ find_file_in_path_option(
 
                // When the file doesn't exist, try adding parts of
                // 'suffixesadd'.
+               NameBufflen = l;
                suffix = suffixes;
                for (;;)
                {
@@ -1920,12 +1923,13 @@ find_file_in_path_option(
                                 || ((find_what == FINDFILE_DIR)
                                                    == mch_isdir(NameBuff))))
                    {
-                       file_name = vim_strnsave(NameBuff, l);
+                       file_name = vim_strnsave(NameBuff, NameBufflen);
                        goto theend;
                    }
                    if (*suffix == NUL)
                        break;
-                   l += copy_option_part(&suffix, NameBuff + l, MAXPATHL - l, ",");
+                   NameBufflen = l + copy_option_part(&suffix, NameBuff + l,
+                                                           MAXPATHL - l, ",");
                }
            }
        }
index c974c401476cc7bfa82e3e24fa8e21cde22d57a3..a7c3dc26de7777e8234f0966cfe844e929d5465c 100644 (file)
@@ -222,6 +222,36 @@ func Test_finddir_error()
   call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:')
 endfunc
 
+func Test_findfile_with_suffixesadd()
+  let save_path = &path
+  let save_dir = getcwd()
+  set path=,,
+  call mkdir('Xfinddir1', 'pR')
+  cd Xfinddir1
+
+  call writefile([], 'foo.c', 'D')
+  call writefile([], 'bar.cpp', 'D')
+  call writefile([], 'baz.cc', 'D')
+  call writefile([], 'foo.o', 'D')
+  call writefile([], 'bar.o', 'D')
+  call writefile([], 'baz.o', 'D')
+
+  set suffixesadd=.c,.cpp
+  call assert_equal('foo.c', findfile('foo'))
+  call assert_equal('./foo.c', findfile('./foo'))
+  call assert_equal('bar.cpp', findfile('bar'))
+  call assert_equal('./bar.cpp', findfile('./bar'))
+  call assert_equal('', findfile('baz'))
+  call assert_equal('', findfile('./baz'))
+  set suffixesadd+=.cc
+  call assert_equal('baz.cc', findfile('baz'))
+  call assert_equal('./baz.cc', findfile('./baz'))
+
+  set suffixesadd&
+  call chdir(save_dir)
+  let &path = save_path
+endfunc
+
 " Test for the :find, :sfind and :tabfind commands
 func Test_find_cmd()
   new
index cc12b3618feb06e70e8fe7bd1a3ad4decab85f25..4dc01c925b43798cd3eff60877467781b25ae391 100644 (file)
@@ -353,4 +353,36 @@ func Test_gf_switchbuf()
   %bw!
 endfunc
 
+func Test_gf_with_suffixesadd()
+  let cwd = getcwd()
+  let dir = 'Xtestgf_sua_dir'
+  call mkdir(dir, 'R')
+  call chdir(dir)
+
+  call writefile([], 'foo.c', 'D')
+  call writefile([], 'bar.cpp', 'D')
+  call writefile([], 'baz.cc', 'D')
+  call writefile([], 'foo.o', 'D')
+  call writefile([], 'bar.o', 'D')
+  call writefile([], 'baz.o', 'D')
+
+  new
+  setlocal path=,, suffixesadd=.c,.cpp
+  call setline(1, ['./foo', './bar', './baz'])
+  exe "normal! gg\<C-W>f"
+  call assert_equal('foo.c', expand('%:t'))
+  close
+  exe "normal! 2gg\<C-W>f"
+  call assert_equal('bar.cpp', expand('%:t'))
+  close
+  call assert_fails('exe "normal! 3gg\<C-W>f"', 'E447:')
+  setlocal suffixesadd+=.cc
+  exe "normal! 3gg\<C-W>f"
+  call assert_equal('baz.cc', expand('%:t'))
+  close
+
+  %bwipe!
+  call chdir(cwd)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 620e7b26f5c69c332df547c4b4b0075c108516a5..4a9af920b2f09c61d62d522f55aff76b7b079b49 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1135,
 /**/
     1134,
 /**/