Skip to content

Commit

Permalink
Remove trailing carriage returns from answers (#559)
Browse files Browse the repository at this point in the history
`comms.Question` removes the tailing '\n' (added when pressing enter),
hence callers expect a result where the result of pressing "enter" when
answering is removed.

However, on Windows, pressing enter adds not only `\n` but `\r\n`, causing
the code that compare the output with a given string work only on unix and
ios. (causing, e.g. #558)
  • Loading branch information
FabienTregan authored and nywilken committed Jun 19, 2018
1 parent 73a9898 commit eb19ecd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion comms/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (q Question) Read(r io.Reader) (string, error) {
if err != nil {
return "", err
}
s = strings.Trim(s, "\n")
s = strings.TrimSpace(s)
if s == "" {
return q.DefaultValue, nil
}
Expand Down
3 changes: 3 additions & 0 deletions comms/question_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func TestQuestion(t *testing.T) {
}{
{"records interactive response", "hello\n", "", "hello"},
{"responds with default if response is empty", "\n", "Fine.", "Fine."},
{"removes trailing \\r in addition to trailing \\", "hello\r\n", "Fine.", "hello"},
{"removes trailing white spaces", "hello \n", "Fine.", "hello"},
{"falls back to default value", " \n", "Default", "Default"},
}
for _, test := range tests {
q := &Question{
Expand Down

0 comments on commit eb19ecd

Please sign in to comment.