diff --git a/src/cargo/ops/registry/login.rs b/src/cargo/ops/registry/login.rs index a3b23d20398..0db134a6da6 100644 --- a/src/cargo/ops/registry/login.rs +++ b/src/cargo/ops/registry/login.rs @@ -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); } diff --git a/tests/testsuite/credential_process.rs b/tests/testsuite/credential_process.rs index d1ab8a97333..b097d9da0ae 100644 --- a/tests/testsuite/credential_process.rs +++ b/tests/testsuite/credential_process.rs @@ -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(); diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index 8ed6802f653..7bfd2b4634b 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -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: