Skip to content

Commit

Permalink
Merge pull request blackbeam#259 from altmannmarcelo/empty-db
Browse files Browse the repository at this point in the history
Usability improvement: leading forward slash empty database
  • Loading branch information
blackbeam authored Sep 9, 2023
2 parents f3cdaa0 + 2a716a6 commit 4f09530
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,11 +1340,14 @@ fn get_opts_pass_from_url(url: &Url) -> Option<String> {

fn get_opts_db_name_from_url(url: &Url) -> Option<String> {
if let Some(mut segments) = url.path_segments() {
segments.next().map(|db_name| {
percent_decode(db_name.as_ref())
.decode_utf8_lossy()
.into_owned()
})
segments
.next()
.map(|db_name| {
percent_decode(db_name.as_ref())
.decode_utf8_lossy()
.into_owned()
})
.and_then(|db| if db.is_empty() { None } else { Some(db) })
} else {
None
}
Expand Down Expand Up @@ -1813,4 +1816,18 @@ mod test {
let opts = Opts::from_url("mysql://localhost/foo?compression=9").unwrap();
assert_eq!(opts.compression(), Some(crate::Compression::new(9)));
}

#[test]
fn test_builder_eq_url_empty_db() {
let builder = super::OptsBuilder::default();
let builder_opts = Opts::from(builder);

let url: &str = "mysql://iq-controller@localhost";
let url_opts = super::Opts::from_str(url).unwrap();
assert_eq!(url_opts.db_name(), builder_opts.db_name());

let url: &str = "mysql://iq-controller@localhost/";
let url_opts = super::Opts::from_str(url).unwrap();
assert_eq!(url_opts.db_name(), builder_opts.db_name());
}
}

0 comments on commit 4f09530

Please sign in to comment.