From 68d791e56d6fb2c4b430041749c9be33933e12e4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 12 Apr 2023 21:16:03 +0200 Subject: [PATCH] cli/command: ConfigureAuth: trim whitespace both for username and password changes readInput() to trim whitespace. The existing code tried to be conservative and only trimmed whitespace for username (not for password). Passwords with leading/trailing whitespace would be _very_ unlikely, and trimming whitespace is generally accepted. Signed-off-by: Sebastiaan van Stijn --- cli/command/registry.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index 621a6c7fc5..243e26c928 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -118,7 +118,6 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes if err != nil { return err } - flUser = strings.TrimSpace(flUser) if flUser == "" { flUser = authconfig.Username } @@ -153,13 +152,14 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes } // readInput reads, and returns user input from in. It tries to return a -// single line, not including the end-of-line bytes. +// single line, not including the end-of-line bytes, and trims leading +// and trailing whitespace. func readInput(in io.Reader) (string, error) { line, _, err := bufio.NewReader(in).ReadLine() if err != nil { return "", errors.Wrap(err, "error while reading input") } - return string(line), nil + return strings.TrimSpace(string(line)), nil } func promptWithDefault(out io.Writer, prompt string, configDefault string) {