[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-45-g7cd17ad

Freddy Vulto fvulto at gmail.com
Sun Mar 27 20:10:37 UTC 2011


The following commit has been merged in the master branch:
commit 7cd17ada11fcb6a270b25f673f9b77918fe055a4
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Sun Mar 27 22:08:55 2011 +0200

    Fix __reassemble_comp_words_by_ref() unquoted pattern removal
    Commit 8227e76 was failing on these `chown' tests in bash-4.1:
    
        FAIL: Check preserve special chars in funky\ user:Debia<TAB>
        FAIL: Check preserve special chars in funky\.user:Debia<TAB>
        FAIL: Check preserve special chars in fu\ nky.user:Debia<TAB>
        FAIL: Check preserve special chars in f\ o\ o\.\bar:Debia<TAB>
        FAIL: Check preserve special chars in foo\_b\ a\.r\ :Debia<TAB>
    
    because a removal pattern is expanded:
    
        $ a=\\b
        $ w=\\
        $ echo ${a#$w}    # Doesn't work
        \b
        $ echo ${a#"$w"}  # Ok
        b

diff --git a/bash_completion b/bash_completion
index dd61e9d..096e82f 100644
--- a/bash_completion
+++ b/bash_completion
@@ -310,8 +310,8 @@ __reassemble_comp_words_by_ref() {
                 eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
                 # Indicate new cword
                 [ $i = $COMP_CWORD ] && eval $3=$j
-                # Remove whitespace (optional) + word separator from line copy
-                line=${line#*${COMP_WORDS[$i]}}
+                # Remove optional whitespace + word separator from line copy
+                line=${line#*"${COMP_WORDS[$i]}"}
                 # Start new word if word separator in original line is
                 # followed by whitespace.
                 [[ ${line:0:1} == ' ' || ${line:0:1} == $'\t' ]] && ((j++))
@@ -322,8 +322,8 @@ __reassemble_comp_words_by_ref() {
             # Append word to current word
             ref="$2[$j]"
             eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
-            # Remove whitespace (optional) + word from line copy
-            line=${line#*${COMP_WORDS[i]}}
+            # Remove optional whitespace + word from line copy
+            line=${line#*"${COMP_WORDS[i]}"}
             # Indicate new cword
             [[ $i == $COMP_CWORD ]] && eval $3=$j
         done
diff --git a/test/unit/_get_comp_words_by_ref.exp b/test/unit/_get_comp_words_by_ref.exp
index 2aa0ae9..9a12d8a 100644
--- a/test/unit/_get_comp_words_by_ref.exp
+++ b/test/unit/_get_comp_words_by_ref.exp
@@ -438,4 +438,19 @@ assert_bash_list {"a b :c"} $cmd $test
 sync_after_int
 
 
+set test {a b\ :c| with WORDBREAKS -= :};  # | = cursor position
+if {[lindex $::BASH_VERSINFO 0] <= 3} {
+    set cmd {COMP_WORDS=(a "b\\ :c"); COMP_CWORD=1}
+} else {
+    set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3}
+}
+append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7}
+assert_bash_exec $cmd $test
+set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
+assert_bash_list {a "b\\ :c"} $cmd $test
+
+
+sync_after_int
+
+
 teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list