From b1e58b1a0e4fdd88df3d1a3feae9adea8cc4e350 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Thu, 10 Dec 2009 21:28:24 +0100 Subject: [PATCH] Fix __reassemble_comp_words_by_ref() If a word is made up of multiple word separator characters: $ a b:: # CWORDS are: a, b, and :: (correct) __reassemble_comp_words_by_ref() couldn't handle this. It assumed CWORDS were: $ a b:: # CWORDS: a, b, : and : (but they're not) Added test case for this. To run the automated tests: ./runUnit _get_cword.exp --- bash_completion | 6 +++--- test/unit/_get_cword.exp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bash_completion b/bash_completion index d82b287d..7e3403c3 100644 --- a/bash_completion +++ b/bash_completion @@ -234,9 +234,9 @@ __reassemble_comp_words_by_ref() { # Yes, list of word completion separators has shrunk; # Re-assemble words to complete for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do - # Is current word not word 0 (the command itself) and is word of - # length 1 and is word newly excluded from being word separator? - while [[ $i -gt 0 && ${#COMP_WORDS[$i]} == 1 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do + # Is current word not word 0 (the command itself) and is word made up of + # just word separators characters to be excluded? + while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} ]]; do [ $j -ge 2 ] && ((j--)) # Append word separator to current word ref="$2[$j]" diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp index eaa62cb8..cd2184ed 100644 --- a/test/unit/_get_cword.exp +++ b/test/unit/_get_cword.exp @@ -171,6 +171,19 @@ assert_bash_list : $cmd $test sync_after_int +set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position +if {[lindex $::BASH_VERSINFO 0] <= 3} { + set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1} +} else { + set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2} +}; # if +append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :} +assert_bash_list b:: $cmd $test + + +sync_after_int + + # This test makes sure `_get_cword' doesn't use `echo' to return it's value, # because -n might be interpreted by `echo' and thus will not be returned. set test "a -n| should return -n"; # | = cursor position