[Bash-completion-commits] [bash-completion] 01/01: __get_cword: avoid $index < 0 (Alioth: #315107)

Ville Skyttä scop-guest at moszumanska.debian.org
Wed Jul 8 12:52:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

scop-guest pushed a commit to branch master
in repository bash-completion.

commit fa1ad7dff9e7099b14552a8782181e9b00f89cc2
Author: Ondrej Oprala <ooprala at redhat.com>
Date:   Wed Jul 8 09:40:14 2015 +0200

    __get_cword: avoid $index < 0 (Alioth: #315107)
    
    Modified-by: Ville Skyttä <ville.skytta at iki.fi>
    Signed-off-by: Ondrej Oprala <ooprala at redhat.com>
---
 bash_completion                                            |  8 ++++----
 test/fixtures/_get_cword/sea                               |  0
 test/fixtures/_get_cword/seb                               |  0
 test/fixtures/_get_cword/sec                               |  0
 .../_get_cword/\303\244\303\244\303\244\303\244\302\247"   |  0
 test/unit/_get_cword.exp                                   | 14 ++++++++++++++
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/bash_completion b/bash_completion
index 3f786af..5f3c7f5 100644
--- a/bash_completion
+++ b/bash_completion
@@ -320,8 +320,8 @@ __get_cword_at_cursor_by_ref()
             ]]; do
                 # Strip first character
                 cur="${cur:1}"
-                # Decrease cursor position
-                ((index--))
+                # Decrease cursor position, staying >= 0
+                [[ $index -gt 0 ]] && ((index--))
             done
 
             # Does found word match cword?
@@ -450,8 +450,8 @@ _get_cword()
             ]]; do
                 # Strip first character
                 cur="${cur:1}"
-                # Decrease cursor position
-                ((index--))
+                # Decrease cursor position, staying >= 0
+                [[ $index -gt 0 ]] && ((index--))
             done
 
             # Does found word matches cword?
diff --git a/test/fixtures/_get_cword/sea b/test/fixtures/_get_cword/sea
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/_get_cword/seb b/test/fixtures/_get_cword/seb
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/_get_cword/sec b/test/fixtures/_get_cword/sec
new file mode 100644
index 0000000..e69de29
diff --git "a/test/fixtures/_get_cword/\303\244\303\244\303\244\303\244\302\247" "b/test/fixtures/_get_cword/\303\244\303\244\303\244\303\244\302\247"
new file mode 100644
index 0000000..e69de29
diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp
index 3a58281..7640298 100644
--- a/test/unit/_get_cword.exp
+++ b/test/unit/_get_cword.exp
@@ -249,4 +249,18 @@ expect {
 sync_after_int
 
 
+set test "index shouldn't drop below 0"
+set dir $::srcdir/fixtures/_get_cword
+set cmd "scp"
+send "$cmd ääää§ se\t\r\n"
+expect {
+    -re "index: substring expression < 0" { fail "$test" }
+    -re /@ { pass "$test" }
+    default { unresolved "$test" }
+}
+
+
+sync_after_int
+
+
 teardown

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/bash-completion/bash-completion.git



More information about the Bash-completion-commits mailing list