Skip to content

Commit

Permalink
Fix prompts with Windows line endings (sigstore#2674)
Browse files Browse the repository at this point in the history
Signed-off-by: Zachary Newman <zjn@chainguard.dev>
  • Loading branch information
znewman01 authored and dmitris committed Mar 24, 2023
1 parent f7a3591 commit e6d1d85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (w *Env) prompt() error {
return err
}

value := strings.Trim(r, "\n")
value := strings.Trim(r, "\r\n")
switch strings.ToLower(value) {
case "y":
return nil
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestConfirm(t *testing.T) {
{"default", "\n", &ui.ErrPromptDeclined{}, "user declined"},
{"empty", "", &ui.ErrPromptDeclined{}, "user declined"},
{"invalid", "yy", &ui.ErrInvalidInput{Got: "yy", Allowed: "y, n"}, "invalid input"},
{"no-windows", "n\r\n", &ui.ErrPromptDeclined{}, "user declined"},
{"yes-windows", "y\r\n", nil, ""},
{"default-windows", "\r\n", &ui.ErrPromptDeclined{}, "user declined"},
{"invalid", "yy\r\n", &ui.ErrInvalidInput{Got: "yy", Allowed: "y, n"}, "invalid input"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit e6d1d85

Please sign in to comment.