diff --git a/bash_completion b/bash_completion index 3f786af9..5f3c7f5f 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 00000000..e69de29b diff --git a/test/fixtures/_get_cword/seb b/test/fixtures/_get_cword/seb new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/_get_cword/sec b/test/fixtures/_get_cword/sec new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/_get_cword/ääää§ b/test/fixtures/_get_cword/ääää§ new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/_get_cword.exp b/test/unit/_get_cword.exp index 3a582811..76402982 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