summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNir Lichtman <nir@lichtman.org>2022-11-12 17:00:31 +0000
committerBram Moolenaar <Bram@vim.org>2022-11-12 17:00:31 +0000
commitb3052aa1b555ab5a81b1459a4972290381b0e7e4 (patch)
tree93bf7597b5c636a2824a9020602fe25c6b664206
parent6600447c7b0a1be3a64d07a318bacdfaae0cac4b (diff)
downloadvim-git-b3052aa1b555ab5a81b1459a4972290381b0e7e4.tar.gz
patch 9.0.0865: duplicate arguments are not always detectedv9.0.0865
Problem: Duplicate arguments are not always detected. Solution: Expand to full path before comparing arguments. (Nir Lichtman, closes #11505, closes #9402)
-rw-r--r--src/arglist.c22
-rw-r--r--src/testdir/test_arglist.vim10
-rw-r--r--src/version.c2
3 files changed, 33 insertions, 1 deletions
diff --git a/src/arglist.c b/src/arglist.c
index bc51cded1..b35cdfe7a 100644
--- a/src/arglist.c
+++ b/src/arglist.c
@@ -784,9 +784,25 @@ ex_argdedupe(exarg_T *eap UNUSED)
int j;
for (i = 0; i < ARGCOUNT; ++i)
+ {
+ // 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)
- if (fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0)
+ {
+ 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);
mch_memmove(ARGLIST + j, ARGLIST + j + 1,
(ARGCOUNT - j - 1) * sizeof(aentry_T));
@@ -799,6 +815,10 @@ ex_argdedupe(exarg_T *eap UNUSED)
--j;
}
+ }
+
+ vim_free(firstFullname);
+ }
}
/*
diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim
index 1bc556fa9..edc8b7742 100644
--- a/src/testdir/test_arglist.vim
+++ b/src/testdir/test_arglist.vim
@@ -420,15 +420,19 @@ func Test_argdedupe()
call Reset_arglist()
argdedupe
call assert_equal([], argv())
+
args a a a aa b b a b aa
argdedupe
call assert_equal(['a', 'aa', 'b'], argv())
+
args a b c
argdedupe
call assert_equal(['a', 'b', 'c'], argv())
+
args a
argdedupe
call assert_equal(['a'], argv())
+
args a A b B
argdedupe
if has('fname_case')
@@ -436,11 +440,17 @@ func Test_argdedupe()
else
call assert_equal(['a', 'b'], argv())
endif
+
args a b a c a b
last
argdedupe
next
call assert_equal('c', expand('%:t'))
+
+ args a ./a
+ argdedupe
+ call assert_equal(['a'], argv())
+
%argd
endfunc
diff --git a/src/version.c b/src/version.c
index a0c4371ce..98e7fd0b5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 865,
+/**/
864,
/**/
863,