diff --git a/src/authenticator_delegate.rs b/src/authenticator_delegate.rs index 0fd2fca..78302d9 100644 --- a/src/authenticator_delegate.rs +++ b/src/authenticator_delegate.rs @@ -142,7 +142,11 @@ pub trait AuthenticatorDelegate { url); let mut code = String::new(); - io::stdin().read_line(&mut code).ok().map(|_| code) + io::stdin().read_line(&mut code).ok().map(|_| { + // Remove newline + code.pop(); + code + }) } else { println!("Please direct your browser to {} and follow the instructions displayed \ there.", diff --git a/src/installed.rs b/src/installed.rs index 87f1377..aa54ce3 100644 --- a/src/installed.rs +++ b/src/installed.rs @@ -181,9 +181,14 @@ impl InstalledFlow Result::Err(Box::new(io::Error::new(io::ErrorKind::UnexpectedEof, "couldn't read code"))) } - // Remove newline Some(mut code) => { - code.pop(); + // Partial backwards compatibilty in case an implementation adds a new line + // due to previous behaviour. + let ends_with_newline = + code.chars().last().map(|c| c == '\n').unwrap_or(false); + if ends_with_newline { + code.pop(); + } Result::Ok(code) } }