mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
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:
parent
ca07158949
commit
727ebf0b38
@ -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"));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user