From 5504db916f2381e8477222d42e9980eeff5e2a44 Mon Sep 17 00:00:00 2001 From: pm-trey <127399938+pm-trey@users.noreply.github.com> Date: Sat, 4 May 2024 00:42:24 -0500 Subject: [PATCH] Parse passwords with special chars correctly (#291) --- replibyte/src/config.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/replibyte/src/config.rs b/replibyte/src/config.rs index 547f12cc..b6d5e2e6 100644 --- a/replibyte/src/config.rs +++ b/replibyte/src/config.rs @@ -424,7 +424,9 @@ fn get_username(url: &Url) -> Result { fn get_password(url: &Url) -> Result { match url.password() { - Some(password) => Ok(password.to_string()), + Some(password) => Ok(percent_decode_str(&password) + .decode_utf8_lossy() + .to_string()), None => Ok(String::new()), // no password } } @@ -619,6 +621,20 @@ mod tests { ) } + #[test] + fn parse_postgres_connection_uri_with_password_with_special_chars_db() { + assert_eq!( + parse_connection_uri("postgres://root:%aqdz^e@localhost:5432/db").unwrap(), + ConnectionUri::Postgres( + "localhost".to_string(), + 5432, + "root".to_string(), + "%aqdz^e".to_string(), + "db".to_string(), + ), + ) + } + #[test] fn parse_mongodb_connection_uri() { assert!(parse_connection_uri("mongodb://root:password").is_err());