Fix panic: runtime error: slice bounds out of range (#94)

Reslicing line[10:] went wrong if only 'setprompt' was entered, without a space after.
This commit is contained in:
Remi Reuvekamp 2016-11-06 05:23:43 +01:00 committed by chzyer
parent 25c2772d5f
commit c914be64f0
1 changed files with 2 additions and 3 deletions

View File

@ -127,12 +127,11 @@ func main() {
println("you set:", strconv.Quote(string(pswd)))
}
case strings.HasPrefix(line, "setprompt"):
prompt := line[10:]
if prompt == "" {
if len(line) <= 10 {
log.Println("setprompt <prompt>")
break
}
l.SetPrompt(prompt)
l.SetPrompt(line[10:])
case strings.HasPrefix(line, "say"):
line := strings.TrimSpace(line[3:])
if len(line) == 0 {