diff --git a/src/main.rs b/src/main.rs index 85d299b..6d41021 100644 --- a/src/main.rs +++ b/src/main.rs @@ -464,7 +464,10 @@ fn decode_token( buffer }) - .unwrap(); + .unwrap() + .trim() + .to_owned(); + let secret_validator = create_validations(algorithm); ( diff --git a/tests/jwt-cli.rs b/tests/jwt-cli.rs index 2aa3535..3a2f451 100644 --- a/tests/jwt-cli.rs +++ b/tests/jwt-cli.rs @@ -469,6 +469,21 @@ mod tests { assert!(result.is_ok()); } + #[test] + fn decodes_a_token_with_leading_and_trailing_whitespace() { + let matches = config_options() + .get_matches_from_safe(vec![ + "jwt", + "decode", + " eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.SEQijh6tEuOOAAKpHPuKxgFqEvlTNP1jj4FUNoBwXaM ", + ]) + .unwrap(); + let decode_matches = matches.subcommand_matches("decode").unwrap(); + let (result, _, _) = decode_token(&decode_matches); + + assert!(result.is_ok()); + } + #[test] fn encodes_and_decodes_an_rsa_token_using_key_from_file() { let body: String = "{\"field\":\"value\"}".to_string();