From a3b322c8dad92826f6cd061b75a89b03363b3d32 Mon Sep 17 00:00:00 2001 From: Majd Alfhaily Date: Mon, 5 Dec 2022 23:04:44 +0100 Subject: [PATCH] Fix reading from stdin on Windows (#121) --- cmd/common.go | 8 ++++++-- pkg/appstore/appstore_login.go | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index a1db8680..2f4c0e7f 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -69,12 +69,16 @@ func newKeyring(logger log.Logger, passphrase string, interactive bool) (keyring path := strings.Split(s, " unlock ")[1] logger.Log().Msgf("enter passphrase to unlock %s (this is separate from your Apple ID password): ", path) - password, err := term.ReadPassword(int(os.Stdin.Fd())) + bytes, err := term.ReadPassword(int(os.Stdin.Fd())) if err != nil { return "", errors.Wrap(err, "failed to read password") } - return string(password), nil + password := string(bytes) + password = strings.Trim(password, "\n") + password = strings.Trim(password, "\r") + + return password, nil }, }) if err != nil { diff --git a/pkg/appstore/appstore_login.go b/pkg/appstore/appstore_login.go index caf294c4..bb8c194c 100644 --- a/pkg/appstore/appstore_login.go +++ b/pkg/appstore/appstore_login.go @@ -171,7 +171,10 @@ func (a *appstore) promptForAuthCode() (string, error) { return "", errors.Wrap(err, ErrGetData.Error()) } - return strings.Trim(authCode, "\n"), nil + authCode = strings.Trim(authCode, "\n") + authCode = strings.Trim(authCode, "\r") + + return authCode, nil } func (*appstore) authDomain(authCode, guid string) string {