Skip to content

Commit f2bec27

Browse files
committed
fix(_ltrim_colon_completions): do compaction of sparse COMPREPLY
The existing implementation of "_ltrim_colon_completions()" assumes that COMREPLY is a dense array, i.e., all the array subscripts are within the range 0 .. ${#COMPREPLY[@]}-1. However, the highest assigned subcript i can be i >= ${#COMPREPLY[@]} when the array is sparse. In fact, COMPREPLY can be sparse in "_known_hosts_real()" because it unsets an empty elements before calling "_ltrim_colon_completions()".
1 parent f8220fa commit f2bec27

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bash_completion

+3-1
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,12 @@ _get_pword()
515515
#
516516
__ltrim_colon_completions()
517517
{
518+
local i=${#COMPREPLY[*]}
519+
((i == 0)) && return 0
518520
if [[ $1 == *:* && $COMP_WORDBREAKS == *:* ]]; then
519521
# Remove colon-word prefix from COMPREPLY items
520522
local colon_word=${1%"${1##*:}"}
521-
local i=${#COMPREPLY[*]}
523+
COMPREPLY=("${COMPREPLY[@]}")
522524
while ((i-- > 0)); do
523525
COMPREPLY[i]=${COMPREPLY[i]#"$colon_word"}
524526
done

0 commit comments

Comments
 (0)