forked from aniani/vim
patch 9.0.0865: duplicate arguments are not always detected
Problem: Duplicate arguments are not always detected. Solution: Expand to full path before comparing arguments. (Nir Lichtman, closes #11505, closes #9402)
This commit is contained in:
committed by
Bram Moolenaar
parent
6600447c7b
commit
b3052aa1b5
@@ -784,9 +784,25 @@ ex_argdedupe(exarg_T *eap UNUSED)
|
|||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (i = 0; i < ARGCOUNT; ++i)
|
for (i = 0; i < ARGCOUNT; ++i)
|
||||||
for (j = i + 1; j < ARGCOUNT; ++j)
|
|
||||||
if (fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0)
|
|
||||||
{
|
{
|
||||||
|
// Expand each argument to a full path to catch different paths leading
|
||||||
|
// to the same file.
|
||||||
|
char_u *firstFullname = FullName_save(ARGLIST[i].ae_fname, FALSE);
|
||||||
|
if (firstFullname == NULL)
|
||||||
|
return; // out of memory
|
||||||
|
|
||||||
|
for (j = i + 1; j < ARGCOUNT; ++j)
|
||||||
|
{
|
||||||
|
char_u *secondFullname = FullName_save(ARGLIST[j].ae_fname, FALSE);
|
||||||
|
if (secondFullname == NULL)
|
||||||
|
break; // out of memory
|
||||||
|
int areNamesDuplicate =
|
||||||
|
fnamecmp(firstFullname, secondFullname) == 0;
|
||||||
|
vim_free(secondFullname);
|
||||||
|
|
||||||
|
if (areNamesDuplicate)
|
||||||
|
{
|
||||||
|
// remove one duplicate argument
|
||||||
vim_free(ARGLIST[j].ae_fname);
|
vim_free(ARGLIST[j].ae_fname);
|
||||||
mch_memmove(ARGLIST + j, ARGLIST + j + 1,
|
mch_memmove(ARGLIST + j, ARGLIST + j + 1,
|
||||||
(ARGCOUNT - j - 1) * sizeof(aentry_T));
|
(ARGCOUNT - j - 1) * sizeof(aentry_T));
|
||||||
@@ -801,6 +817,10 @@ ex_argdedupe(exarg_T *eap UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim_free(firstFullname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":argedit"
|
* ":argedit"
|
||||||
*/
|
*/
|
||||||
|
@@ -420,15 +420,19 @@ func Test_argdedupe()
|
|||||||
call Reset_arglist()
|
call Reset_arglist()
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal([], argv())
|
call assert_equal([], argv())
|
||||||
|
|
||||||
args a a a aa b b a b aa
|
args a a a aa b b a b aa
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a', 'aa', 'b'], argv())
|
call assert_equal(['a', 'aa', 'b'], argv())
|
||||||
|
|
||||||
args a b c
|
args a b c
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a', 'b', 'c'], argv())
|
call assert_equal(['a', 'b', 'c'], argv())
|
||||||
|
|
||||||
args a
|
args a
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a'], argv())
|
call assert_equal(['a'], argv())
|
||||||
|
|
||||||
args a A b B
|
args a A b B
|
||||||
argdedupe
|
argdedupe
|
||||||
if has('fname_case')
|
if has('fname_case')
|
||||||
@@ -436,11 +440,17 @@ func Test_argdedupe()
|
|||||||
else
|
else
|
||||||
call assert_equal(['a', 'b'], argv())
|
call assert_equal(['a', 'b'], argv())
|
||||||
endif
|
endif
|
||||||
|
|
||||||
args a b a c a b
|
args a b a c a b
|
||||||
last
|
last
|
||||||
argdedupe
|
argdedupe
|
||||||
next
|
next
|
||||||
call assert_equal('c', expand('%:t'))
|
call assert_equal('c', expand('%:t'))
|
||||||
|
|
||||||
|
args a ./a
|
||||||
|
argdedupe
|
||||||
|
call assert_equal(['a'], argv())
|
||||||
|
|
||||||
%argd
|
%argd
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
865,
|
||||||
/**/
|
/**/
|
||||||
864,
|
864,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user