Skip to content

Commit

Permalink
Fix test for pos greater than text length
Browse files Browse the repository at this point in the history
If the pos is greater than the text length in runes, it will cause a
crash in refresh. This typo was introduced in the original version of
PromptWithSuggestion.

Fixes #106
  • Loading branch information
peterh committed Jun 19, 2018
1 parent 80ce870 commit 8c1271f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions line.go
Expand Up @@ -596,7 +596,7 @@ func (s *State) Prompt(prompt string) (string, error) {

// PromptWithSuggestion displays prompt and an editable text with cursor at
// given position. The cursor will be set to the end of the line if given position
// is negative or greater than length of text. Returns a line of user input, not
// is negative or greater than length of text (in runes). Returns a line of user input, not
// including a trailing newline character. An io.EOF error is returned if the user
// signals end-of-file by pressing Ctrl-D.
func (s *State) PromptWithSuggestion(prompt string, text string, pos int) (string, error) {
Expand Down Expand Up @@ -631,8 +631,8 @@ func (s *State) PromptWithSuggestion(prompt string, text string, pos int) (strin

defer s.stopPrompt()

if pos < 0 || len(text) < pos {
pos = len(text)
if pos < 0 || len(line) < pos {
pos = len(line)
}
if len(line) > 0 {
err := s.refresh(p, line, pos)
Expand Down

0 comments on commit 8c1271f

Please sign in to comment.