Skip to content

Commit

Permalink
Parse passwords with special chars correctly (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-trey authored May 4, 2024
1 parent 1476dd7 commit 5504db9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion replibyte/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ fn get_username(url: &Url) -> Result<String, Error> {

fn get_password(url: &Url) -> Result<String, Error> {
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
}
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 5504db9

Please sign in to comment.