Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/command/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
}
}

argPassword = strings.TrimSpace(argPassword)
if argPassword == "" {
isEmpty := strings.TrimSpace(argPassword) == ""
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change avoids trimming argPassword, but passwords entered interactively are still trimmed because prompt.ReadInput() applies strings.TrimSpace(scanner.Text()) (internal/prompt/prompt.go:58). As a result, leading/trailing whitespace in passwords will still be lost when the password is prompted, which contradicts the PR’s goal of preserving whitespace. Consider adding a non-trimming prompt function (or an option/flag to ReadInput) for secrets so the returned password preserves whitespace (while still stripping the final line-ending).

Suggested change
isEmpty := strings.TrimSpace(argPassword) == ""
isEmpty := argPassword == ""

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional; a whitespace-only password should not be considered valid, and so ignored here (to handle accidental user-input)

if isEmpty {
restoreInput, err := prompt.DisableInputEcho(cli.In())
if err != nil {
return registrytypes.AuthConfig{}, err
Expand Down
50 changes: 50 additions & 0 deletions cli/command/registry/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,56 @@ func TestRunLogin(t *testing.T) {
},
},
},
{
doc: "password with leading and trailing spaces",
priorCredentials: map[string]configtypes.AuthConfig{},
input: loginOptions{
serverAddress: "reg1",
user: "my-username",
password: " my password with spaces ",
},
expectedCredentials: map[string]configtypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: " my password with spaces ",
ServerAddress: "reg1",
},
},
},
{
doc: "password stdin with line-endings",
priorCredentials: map[string]configtypes.AuthConfig{},
stdIn: " my password with spaces \r\n",
input: loginOptions{
serverAddress: "reg1",
user: "my-username",
passwordStdin: true,
},
expectedCredentials: map[string]configtypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: " my password with spaces ",
ServerAddress: "reg1",
},
},
},
{
doc: "password stdin with multiple line-endings",
priorCredentials: map[string]configtypes.AuthConfig{},
stdIn: " my password\nwith spaces \r\n\r\n",
input: loginOptions{
serverAddress: "reg1",
user: "my-username",
passwordStdin: true,
},
expectedCredentials: map[string]configtypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: " my password\nwith spaces \r\n",
ServerAddress: "reg1",
},
},
},
}

for _, tc := range testCases {
Expand Down
Loading