Skip to content

Commit

Permalink
fix crash when COMP_POINT is greater than COMP_LINE size (#128)
Browse files Browse the repository at this point in the history
Some shells (inexplicably) occasionally have a COMP_POINT that is greater than the COMP_LINE size. When that happens completion should be based on length of the COMP_LINE to avoid an out of bounds error.

See the original hack fix here: https://github.com/chriswalz/bit/blob/master/cmd/bitcomplete.go on line 39
  • Loading branch information
chriswalz authored Nov 8, 2020
1 parent 5c05e97 commit 246bd25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func Complete(name string, cmd Completer) {
if err != nil {
panic("COMP_POINT env should be integer, got: " + point)
}
if i > len(line) {
i = len(line)
}

// Parse the command line up to the completion point.
args := arg.Parse(line[:i])
Expand Down
2 changes: 1 addition & 1 deletion complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestComplete(t *testing.T) {
{shouldExit: false, line: "", point: ""},
{shouldPanic: true, line: "cmd", point: ""},
{shouldPanic: true, line: "cmd", point: "a"},
{shouldPanic: true, line: "cmd", point: "4"},
{shouldExit: true, line: "cmd", point: "4"},

{shouldExit: true, install: "1"},
{shouldExit: false, install: "a"},
Expand Down

0 comments on commit 246bd25

Please sign in to comment.