Skip to content

Commit bf595ae

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.1135: 'suffixesadd' doesn't work with multiple items
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 51eefba commit bf595ae

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

src/findfile.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ vim_findfile(void *search_ctx_arg)
10821082
* Try without extra suffix and then with suffixes
10831083
* from 'suffixesadd'.
10841084
*/
1085+
len = file_path.length;
10851086
if (search_ctx->ffsc_tagfile)
10861087
suf = (char_u *)"";
10871088
else
@@ -1164,8 +1165,8 @@ vim_findfile(void *search_ctx_arg)
11641165
// Not found or found already, try next suffix.
11651166
if (*suf == NUL)
11661167
break;
1167-
file_path.length += copy_option_part(&suf, file_path.string + file_path.length,
1168-
MAXPATHL - file_path.length, ",");
1168+
file_path.length = len + copy_option_part(&suf,
1169+
file_path.string + len, MAXPATHL - len, ",");
11691170
}
11701171
}
11711172
}
@@ -1872,6 +1873,7 @@ find_file_in_path_option(
18721873
if (first == TRUE)
18731874
{
18741875
int l;
1876+
int NameBufflen;
18751877
int run;
18761878
size_t rel_fnamelen = 0;
18771879
char_u *suffix;
@@ -1912,6 +1914,7 @@ find_file_in_path_option(
19121914

19131915
// When the file doesn't exist, try adding parts of
19141916
// 'suffixesadd'.
1917+
NameBufflen = l;
19151918
suffix = suffixes;
19161919
for (;;)
19171920
{
@@ -1920,12 +1923,13 @@ find_file_in_path_option(
19201923
|| ((find_what == FINDFILE_DIR)
19211924
== mch_isdir(NameBuff))))
19221925
{
1923-
file_name = vim_strnsave(NameBuff, l);
1926+
file_name = vim_strnsave(NameBuff, NameBufflen);
19241927
goto theend;
19251928
}
19261929
if (*suffix == NUL)
19271930
break;
1928-
l += copy_option_part(&suffix, NameBuff + l, MAXPATHL - l, ",");
1931+
NameBufflen = l + copy_option_part(&suffix, NameBuff + l,
1932+
MAXPATHL - l, ",");
19291933
}
19301934
}
19311935
}

src/testdir/test_findfile.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,36 @@ func Test_finddir_error()
222222
call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:')
223223
endfunc
224224

225+
func Test_findfile_with_suffixesadd()
226+
let save_path = &path
227+
let save_dir = getcwd()
228+
set path=,,
229+
call mkdir('Xfinddir1', 'pR')
230+
cd Xfinddir1
231+
232+
call writefile([], 'foo.c', 'D')
233+
call writefile([], 'bar.cpp', 'D')
234+
call writefile([], 'baz.cc', 'D')
235+
call writefile([], 'foo.o', 'D')
236+
call writefile([], 'bar.o', 'D')
237+
call writefile([], 'baz.o', 'D')
238+
239+
set suffixesadd=.c,.cpp
240+
call assert_equal('foo.c', findfile('foo'))
241+
call assert_equal('./foo.c', findfile('./foo'))
242+
call assert_equal('bar.cpp', findfile('bar'))
243+
call assert_equal('./bar.cpp', findfile('./bar'))
244+
call assert_equal('', findfile('baz'))
245+
call assert_equal('', findfile('./baz'))
246+
set suffixesadd+=.cc
247+
call assert_equal('baz.cc', findfile('baz'))
248+
call assert_equal('./baz.cc', findfile('./baz'))
249+
250+
set suffixesadd&
251+
call chdir(save_dir)
252+
let &path = save_path
253+
endfunc
254+
225255
" Test for the :find, :sfind and :tabfind commands
226256
func Test_find_cmd()
227257
new

src/testdir/test_gf.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,36 @@ func Test_gf_switchbuf()
353353
%bw!
354354
endfunc
355355

356+
func Test_gf_with_suffixesadd()
357+
let cwd = getcwd()
358+
let dir = 'Xtestgf_sua_dir'
359+
call mkdir(dir, 'R')
360+
call chdir(dir)
361+
362+
call writefile([], 'foo.c', 'D')
363+
call writefile([], 'bar.cpp', 'D')
364+
call writefile([], 'baz.cc', 'D')
365+
call writefile([], 'foo.o', 'D')
366+
call writefile([], 'bar.o', 'D')
367+
call writefile([], 'baz.o', 'D')
368+
369+
new
370+
setlocal path=,, suffixesadd=.c,.cpp
371+
call setline(1, ['./foo', './bar', './baz'])
372+
exe "normal! gg\<C-W>f"
373+
call assert_equal('foo.c', expand('%:t'))
374+
close
375+
exe "normal! 2gg\<C-W>f"
376+
call assert_equal('bar.cpp', expand('%:t'))
377+
close
378+
call assert_fails('exe "normal! 3gg\<C-W>f"', 'E447:')
379+
setlocal suffixesadd+=.cc
380+
exe "normal! 3gg\<C-W>f"
381+
call assert_equal('baz.cc', expand('%:t'))
382+
close
383+
384+
%bwipe!
385+
call chdir(cwd)
386+
endfunc
387+
356388
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1135,
707709
/**/
708710
1134,
709711
/**/

0 commit comments

Comments
 (0)