Percent decode MySQL passwords from URL string

Fixes #603.
Adds percent decoding for MySQL passwords for when they contain non-URL
safe passwords, along with a regression test to prevent further
instances of this issue.
This commit is contained in:
Wesley Norris 2020-09-30 20:09:34 -04:00 committed by Ryan Leckey
parent ca07158949
commit 727ebf0b38

View File

@ -24,7 +24,13 @@ impl FromStr for MySqlConnectOptions {
}
if let Some(password) = url.password() {
options = options.password(password);
// Percent decode password in case it contains non-URL safe
// characters (issues #77, #603)
let password = percent_encoding::percent_decode_str(password)
.decode_utf8()
.map_err(|e| Error::Decode(e.into()))?;
options = options.password(&*password);
}
let path = url.path().trim_start_matches('/');
@ -66,3 +72,10 @@ impl FromStr for MySqlConnectOptions {
Ok(options)
}
}
#[test]
fn percent_decodes_password() {
let url_str = "mysql://root:aa@bb@localhost/db";
let options = MySqlConnectOptions::from_str(url_str).unwrap();
assert_eq!(options.password.as_deref(), Some("aa@bb"));
}