Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix: normalize MySQL SSL mode URL params

t8y2cd87d2a4e4a4
diff --git a/crates/dbx-core/src/db/mysql.rs b/crates/dbx-core/src/db/mysql.rs
index 21ab839622..c39c73ce2f 100644
--- a/crates/dbx-core/src/db/mysql.rs
+++ b/crates/dbx-core/src/db/mysql.rs
@@ -630,6 +630,7 @@ fn mysql_async_url(url: &str) -> Cow<'_, str> {
let original_count = query.split('&').filter(|segment| !segment.trim().is_empty()).count();
let mut filtered: Vec<String> = Vec::new();
+ let mut changed = false;
for segment in query.split('&') {
let segment = segment.trim();
if segment.is_empty()
@@ -639,6 +640,7 @@ fn mysql_async_url(url: &str) -> Cow<'_, str> {
|| segment.to_ascii_lowercase().starts_with("connect_timeout=")
|| segment.to_ascii_lowercase().starts_with("connecttimeout=")
{
+ changed = true;
continue;
}
@@ -647,6 +649,7 @@ fn mysql_async_url(url: &str) -> Cow<'_, str> {
continue;
};
if key.eq_ignore_ascii_case("ssl-mode") || key.eq_ignore_ascii_case("sslmode") {
+ changed = true;
match value.to_ascii_lowercase().replace('-', "_").as_str() {
"disabled" | "disable" => filtered.push("require_ssl=false".to_string()),
"required" | "require" => {
@@ -664,12 +667,13 @@ fn mysql_async_url(url: &str) -> Cow<'_, str> {
continue;
}
if is_jdbc_param(key) {
+ changed = true;
continue;
}
filtered.push(segment.to_string());
}
- if filtered.len() == original_count {
+ if !changed && filtered.len() == original_count {
Cow::Borrowed(url)
} else if filtered.is_empty() {
Cow::Owned(base.to_string())
@@ -1397,6 +1401,20 @@ mod tests {
);
}
+ #[test]
+ fn mysql_async_url_translates_disabled_ssl_mode_even_when_param_count_matches() {
+ let url = "mysql://host:3306/db?ssl-mode=disabled";
+
+ assert_eq!(mysql_async_url(url).as_ref(), "mysql://host:3306/db?require_ssl=false");
+ }
+
+ #[test]
+ fn mysql_async_url_translates_verify_identity_ssl_mode_even_when_param_count_matches() {
+ let url = "mysql://host:3306/db?sslmode=verify_identity";
+
+ assert_eq!(mysql_async_url(url).as_ref(), "mysql://host:3306/db?require_ssl=true");
+ }
+
#[test]
fn mysql_async_url_strips_jdbc_params() {
let url = "mysql://host:3306/db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true";