Skip to content

Commit 6207f93

Browse files
committed
fix(credential): trim newlines in token from stdin for credential providers
1 parent a498391 commit 6207f93

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/cargo/ops/registry/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn registry_login(
3939
let mut token_from_stdin = None;
4040
let token = token_from_cmdline.or_else(|| {
4141
if !std::io::stdin().is_terminal() {
42-
let token = std::io::read_to_string(std::io::stdin()).unwrap_or_default();
42+
let token = cargo_credential::read_line().unwrap_or_default();
4343
if !token.is_empty() {
4444
token_from_stdin = Some(token);
4545
}

tests/testsuite/credential_process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ fn login_token_from_stdin() {
709709
.with_stdin("abcdefg\n")
710710
.with_stderr(
711711
r#"[UPDATING] [..]
712-
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg\n","login-url":"[..]"}
712+
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]"}
713713
"#,
714714
)
715715
.run();

tests/testsuite/login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ fn empty_login_token() {
113113
.with_stderr(
114114
"\
115115
[UPDATING] crates.io index
116+
please paste the token found on [..] below
116117
[ERROR] credential provider `cargo:token` failed action `login`
117118
118119
Caused by:

0 commit comments

Comments
 (0)