优化: 代理工具代码审查修复
This commit is contained in:
1 parent
3ee22b1076
commit
091cb65314
9 files changed
+321
-91
No files matched your search
@@ -77,8 +77,38 @@ impl Config {
|
||||
impl ConnectionConfig {
|
||||
pub fn build_url(&self) -> String {
|
||||
match &self.password {
|
||||
Some(pass) => format!("redis://:{}@{}:{}/{}", pass, self.host, self.port, self.db),
|
||||
Some(pass) => format!("redis://:{}@{}:{}/{}", url_encode_password(pass), self.host, self.port, self.db),
|
||||
None => format!("redis://{}:{}/{}", self.host, self.port, self.db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn url_encode_password(s: &str) -> String {
|
||||
let mut result = String::new();
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'@' => result.push_str("%40"),
|
||||
':' => result.push_str("%3A"),
|
||||
'/' => result.push_str("%2F"),
|
||||
'?' => result.push_str("%3F"),
|
||||
'#' => result.push_str("%23"),
|
||||
'[' => result.push_str("%5B"),
|
||||
']' => result.push_str("%5D"),
|
||||
'!' => result.push_str("%21"),
|
||||
'$' => result.push_str("%24"),
|
||||
'&' => result.push_str("%26"),
|
||||
'\'' => result.push_str("%27"),
|
||||
'(' => result.push_str("%28"),
|
||||
')' => result.push_str("%29"),
|
||||
'*' => result.push_str("%2A"),
|
||||
'+' => result.push_str("%2B"),
|
||||
',' => result.push_str("%2C"),
|
||||
';' => result.push_str("%3B"),
|
||||
'=' => result.push_str("%3D"),
|
||||
'%' => result.push_str("%25"),
|
||||
' ' => result.push_str("%20"),
|
||||
_ => result.push(c),
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
Reference in new issue
Block a user