Skip to content

Commit 1326474

Browse files
committed
fix(_comp_uniq): avoid expanding array subscripts in arith context
When the array elements contains a confusing value such as `arr[10]='1],x*=10,a[2'`, (( tmp["${arr[10]}"] )) would be unexpectedly interpreted as ((tmp[1], x *= 10, a[2])) in bash < 5.2. We here instead use an independent parameter expansions and assignments.
1 parent 651a424 commit 1326474

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

completions/ARRAY

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ _comp_xfunc_ARRAY_filter()
154154
_comp_uniq()
155155
{
156156
local -n _comp_uniq__array=$1
157-
local -A _comp_uniq__tmp
157+
local -A _comp_uniq__tmp=()
158158
local -i _comp_uniq__i
159159
for _comp_uniq__i in "${!_comp_uniq__array[@]}"; do
160-
((_comp_uniq__tmp["${_comp_uniq__array[_comp_uniq__i]}"]++ > 0)) &&
160+
[[ ${_comp_uniq__tmp[${_comp_uniq__array[_comp_uniq__i]}]-} ]] &&
161161
unset -v '_comp_uniq__array[_comp_uniq__i]'
162+
_comp_uniq__tmp[${_comp_uniq__array[_comp_uniq__i]}]=set
162163
done
163164
}
164165

0 commit comments

Comments
 (0)