Skip to content

Commit 526b32d

Browse files
committed
fix: strip newline and carriage return when password is read from stdin
Signed-off-by: Nico Beck <[email protected]>
1 parent 3da388c commit 526b32d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/commands/registry.rs

+3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ impl Login {
143143
let mut buf = String::new();
144144
let mut stdin = std::io::stdin().lock();
145145
stdin.read_to_string(&mut buf)?;
146+
// trim trailing newlines and carriage returns (see https://blog.v-gar.de/2019/04/rust-remove-trailing-newline-after-input)
147+
let len = buf.trim_end_matches(&['\r', '\n'][..]).len();
148+
buf.truncate(len);
146149
buf
147150
} else {
148151
match self.password {

0 commit comments

Comments
 (0)