[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-307-gfc96a95

Freddy Vulto fvulto at gmail.com
Thu May 19 20:41:21 UTC 2011


The following commit has been merged in the master branch:
commit fc96a951b783e2a5d4facb2897f9f282bad08e6c
Author: Freddy Vulto <fvulto at gmail.com>
Date:   Thu May 19 22:40:14 2011 +0200

    Fix error "bad array subscript"
    Caused by _get_comp_words_by_ref() with cursor at position 0.
    Patch by Igor Murzov (Debian: #559953)

diff --git a/CHANGES b/CHANGES
index d77900d..0ca0edc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -40,6 +40,8 @@ bash-completion (2.x)
   [ Freddy Vulto ]
   * Improve __reassemble_comp_words_by_ref() to not create words of
     characters-to-exclude (Alioth: #313057)
+  * Improve _get_comp_words_by_ref() with cursor at position 0. Patch by
+    Igor Murzov (Debian: #559953)
 
   [ Mattias Ulbrich ]
   * Make java class completion suggest packages.
diff --git a/bash_completion b/bash_completion
index d294d47..d3507fb 100644
--- a/bash_completion
+++ b/bash_completion
@@ -450,7 +450,7 @@ _get_comp_words_by_ref()
 
     [[ $vcur   ]] && { upvars+=("$vcur"  ); upargs+=(-v $vcur   "$cur"  ); }
     [[ $vcword ]] && { upvars+=("$vcword"); upargs+=(-v $vcword "$cword"); }
-    [[ $vprev  ]] && { upvars+=("$vprev" ); upargs+=(-v $vprev 
+    [[ $vprev && $cword -ge 1 ]] && { upvars+=("$vprev" ); upargs+=(-v $vprev 
         "${words[cword - 1]}"); }
     [[ $vwords ]] && { upvars+=("$vwords"); upargs+=(-a${#words[@]} $vwords
         "${words[@]}"); }
diff --git a/test/unit/_get_comp_words_by_ref.exp b/test/unit/_get_comp_words_by_ref.exp
index 8244796..f5c7ab3 100644
--- a/test/unit/_get_comp_words_by_ref.exp
+++ b/test/unit/_get_comp_words_by_ref.exp
@@ -48,16 +48,27 @@ assert_bash_list {" a"} $cmd $test
 sync_after_int
 
 
-set test "|a ";  # | = cursor position
-set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a '; COMP_POINT=0; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
+set test "|a";  # | = cursor position
+set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a'; COMP_POINT=0; \
+    unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
 assert_bash_list {" "} $cmd $test
 
 
 sync_after_int
 
 
-set test " | a ";  # | = cursor position
-set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='  a '; COMP_POINT=1; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
+set test "|a \$";  # | = cursor position
+set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a '; COMP_POINT=0; \
+    unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
+assert_bash_list {" "} $cmd $test
+
+
+sync_after_int
+
+
+set test " | a \$";  # | = cursor position
+set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='  a '; COMP_POINT=1; \
+    unset cur prev; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
 assert_bash_list {" "} $cmd $test
 
 
diff --git a/test/unit/_init_completion.exp b/test/unit/_init_completion.exp
new file mode 100644
index 0000000..75c4125
--- /dev/null
+++ b/test/unit/_init_completion.exp
@@ -0,0 +1,35 @@
+proc setup {} {
+    save_env
+}
+
+
+proc teardown {} {
+    assert_bash_exec { \
+        unset COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS cur prev words cword\
+    }
+    assert_env_unmodified {
+        /COMPREPLY=/d
+    }
+}
+
+
+setup
+
+
+set test "function should not pollute environment"
+# NOTE: A possible environment pollution is detected by assert_env_modified() in teardown()
+assert_bash_exec {foo() { local cur prev words cword; _init_completion; }; foo; unset foo} $test
+
+
+sync_after_int
+
+
+set test "|a";  # | = cursor position
+set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a'; COMP_POINT=0; _init_completion; echo "$cur $prev"}
+assert_bash_list {" "} $cmd $test
+
+
+sync_after_int
+
+
+teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list