Skip to content

Commit

Permalink
fix(credential): trim newlines in token from stdin for credential pro…
Browse files Browse the repository at this point in the history
…viders
  • Loading branch information
arlosi committed Apr 17, 2024
1 parent a498391 commit 6207f93
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn registry_login(
let mut token_from_stdin = None;
let token = token_from_cmdline.or_else(|| {
if !std::io::stdin().is_terminal() {
let token = std::io::read_to_string(std::io::stdin()).unwrap_or_default();
let token = cargo_credential::read_line().unwrap_or_default();
if !token.is_empty() {
token_from_stdin = Some(token);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ fn login_token_from_stdin() {
.with_stdin("abcdefg\n")
.with_stderr(
r#"[UPDATING] [..]
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg\n","login-url":"[..]"}
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]"}
"#,
)
.run();
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn empty_login_token() {
.with_stderr(
"\
[UPDATING] crates.io index
please paste the token found on [..] below
[ERROR] credential provider `cargo:token` failed action `login`
Caused by:
Expand Down

0 comments on commit 6207f93

Please sign in to comment.