vim-patch:8.1.0133: tagfiles() can have duplicate entries

Problem:    tagfiles() can have duplicate entries.
Solution:   Simplify the filename to make checking for duplicates work better.
            Add a test. (Dominique Pelle, closes vim/vim#2979)
46577b5e54
This commit is contained in:
Jan Edmund Lazo 2019-05-07 03:04:19 -04:00
parent f76792a10b
commit f4e5cd200a
2 changed files with 41 additions and 2 deletions

View File

@ -1970,7 +1970,13 @@ static garray_T tag_fnames = GA_EMPTY_INIT_VALUE;
*/
static void found_tagfile_cb(char_u *fname, void *cookie)
{
GA_APPEND(char_u *, &tag_fnames, vim_strsave(fname));
char_u *const tag_fname = vim_strsave(fname);
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(tag_fname);
#endif
simplify_filename(tag_fname);
GA_APPEND(char_u *, &tag_fnames, tag_fname);
}
#if defined(EXITFREE)
@ -2028,6 +2034,16 @@ get_tagfname (
++tnp->tn_hf_idx;
STRCPY(buf, p_hf);
STRCPY(path_tail(buf), "tags");
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(buf);
#endif
simplify_filename(buf);
for (int i = 0; i < tag_fnames.ga_len; i++) {
if (STRCMP(buf, ((char_u **)(tag_fnames.ga_data))[i]) == 0) {
return FAIL; // avoid duplicate file names
}
}
} else
STRLCPY(buf, ((char_u **)(tag_fnames.ga_data))[
tnp->tn_hf_idx++], MAXPATHL);

View File

@ -1,4 +1,4 @@
" test 'taglist' function and :tags command
" test taglist(), tagfiles() functions and :tags command
func Test_taglist()
call writefile([
@ -74,3 +74,26 @@ func Test_tagsfile_without_trailing_newline()
call delete('Xtags')
endfunc
func Test_tagfiles()
call assert_equal([], tagfiles())
call writefile(["FFoo\tXfoo\t1"], 'Xtags1')
call writefile(["FBar\tXbar\t1"], 'Xtags2')
set tags=Xtags1,Xtags2
call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
help
let tf = tagfiles()
call assert_equal(1, len(tf))
call assert_equal(fnamemodify(expand('$VIMRUNTIME/doc/tags'), ':p:gs?\\?/?'),
\ fnamemodify(tf[0], ':p:gs?\\?/?'))
helpclose
call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
set tags&
call assert_equal([], tagfiles())
call delete('Xtags1')
call delete('Xtags2')
bd
endfunc