Fix __reassemble_comp_words_by_ref()

On bash-3, completing a b c: with COMP_WORDBREAKS -= : would result in the
current word being bc: (Alioth #312190)

Added unit test, run via:

    ./run unit/_get_cword.exp
This commit is contained in:
Freddy Vulto 2009-12-30 09:43:16 +01:00
parent 14588b8491
commit 3251038c9d
2 changed files with 15 additions and 2 deletions

View File

@ -228,8 +228,8 @@ __reassemble_comp_words_by_ref() {
# Re-assemble words to complete # Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
# Is current word not word 0 (the command itself) and is word made up of # Is current word not word 0 (the command itself) and is word made up of
# just word separators characters to be excluded? # just word separator characters to be excluded?
while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} ]]; do
[ $j -ge 2 ] && ((j--)) [ $j -ge 2 ] && ((j--))
# Append word separator to current word # Append word separator to current word
ref="$2[$j]" ref="$2[$j]"

View File

@ -161,6 +161,19 @@ assert_bash_list b:c $cmd $test
sync_after_int sync_after_int
set test {a b c:| with WORDBREAKS -= : should return c:}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} {
set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
}; # if
append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :}
assert_bash_list c: $cmd $test
sync_after_int
set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position
set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :} set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3; _get_cword :}
assert_bash_list : $cmd $test assert_bash_list : $cmd $test