Skip to content

Commit

Permalink
Fix #120, decode username to allow users special chars (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola authored May 19, 2022
1 parent 851cf6c commit b71f6b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions replibyte/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ctrlc = "3.2.1"
reqwest = { version = "0.11", features = ["blocking"] }
chrono = {version = "0.4", features = ["serde"] }
machine-uid = "0.2"
percent-encoding = "2.1.0"

# FIXME removed until the CI release pipeline is fixed
#wasmer = { version = "2.2", optional = true }
Expand Down
19 changes: 18 additions & 1 deletion replibyte/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::transformer::random::RandomTransformer;
use crate::transformer::redacted::{RedactedTransformer, RedactedTransformerOptions};
use crate::transformer::transient::TransientTransformer;
use crate::transformer::Transformer;
use percent_encoding::percent_decode_str;
use serde;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -413,7 +414,9 @@ fn get_port(url: &Url, default_port: u16) -> Result<u16, Error> {

fn get_username(url: &Url) -> Result<String, Error> {
match url.username() {
username if username != "" => Ok(username.to_string()),
username if username != "" => Ok(percent_decode_str(&username)
.decode_utf8_lossy()
.to_string()),
_ => Err(Error::new(
ErrorKind::Other,
"missing <username> property from connection uri",
Expand Down Expand Up @@ -622,6 +625,20 @@ mod tests {
)
}

#[test]
fn parse_postgres_connection_uri_with_username_with_special_chars_db() {
assert_eq!(
parse_connection_uri("postgres://root@azure:password@localhost:5432/db").unwrap(),
ConnectionUri::Postgres(
"localhost".to_string(),
5432,
"root@azure".to_string(),
"password".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 b71f6b8

Please sign in to comment.