Parse empty url database as None (fix
@@ -709,7 +709,10 @@ 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| {
+ segments
+ .next()
+ .filter(|&db_name| !db_name.is_empty())
+ .map(|db_name| {
percent_decode(db_name.as_ref())
.decode_utf8_lossy()
.into_owned()
@@ -853,6 +856,12 @@ mod test {
);
}
+ #[test]
+ fn should_report_empty_url_database_as_none() {
+ let opt = Opts::from("mysql://localhost/");
+ assert_eq!(opt.get_db_name(), None);
+ }
+
#[test]
#[cfg(not(feature = "ssl"))]
fn should_convert_url_into_opts() {
