Merge pull request #75 from posener/fix-slice-bug

Protect line slicing from index out of range
This commit is contained in:
Eyal Posener 2018-10-26 13:48:32 +03:00 committed by GitHub
commit 3ef9b31a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -64,10 +64,12 @@ func (c *Complete) Complete() bool {
return c.CLI.Run()
}
completePhrase := line[:point]
if point >= 0 && point < len(line) {
line = line[:point]
}
Log("Completing phrase: %s", completePhrase)
a := newArgs(completePhrase)
Log("Completing phrase: %s", line)
a := newArgs(line)
Log("Completing last field: %s", a.Last)
options := c.Command.Predict(a)
Log("Options: %s", options)