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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(connection): preserve credentials for credential-free URLs
t8y22ecbac4a6fb0
diff --git a/apps/desktop/src/lib/connection/connectionUrl.ts b/apps/desktop/src/lib/connection/connectionUrl.tsindex a8fd9a691c..dd08222ff4 100644--- a/apps/desktop/src/lib/connection/connectionUrl.ts+++ b/apps/desktop/src/lib/connection/connectionUrl.ts@@ -674,6 +674,11 @@ function zookeeperConnectStringFromUrl(parsed: URL, defaultPort: number): stringreturn `${host}:${port}${chroot}`;}+function shouldPreserveCredentialFreeUrlCredentials(config: Omit<ConnectionConfig, "id">, parsed: ParsedConnectionUrl): boolean {+ const currentProfile = config.driver_profile?.trim();+ return parsed.dbType === config.db_type && (!currentProfile || parsed.driverProfile === currentProfile) && !parsed.username && !parsed.password;+}+function applyParsedUsername(config: Omit<ConnectionConfig, "id">, parsed: ParsedConnectionUrl): string {if (parsed.dbType === "h2" && config.db_type === "h2" && !h2JdbcUrlHasUserParam(parsed.connectionString)) {return config.username || parsed.username;@@ -681,6 +686,9 @@ function applyParsedUsername(config: Omit<ConnectionConfig, "id">, parsed: Parseif (parsed.dbType === "kingbase" && config.db_type === "kingbase" && !parsed.username) {return config.username;}+ if (shouldPreserveCredentialFreeUrlCredentials(config, parsed)) {+ return config.username || parsed.username;+ }return parsed.username;}@@ -691,6 +699,9 @@ function applyParsedPassword(config: Omit<ConnectionConfig, "id">, parsed: Parseif (parsed.dbType === "kingbase" && config.db_type === "kingbase" && !parsed.password) {return config.password;}+ if (shouldPreserveCredentialFreeUrlCredentials(config, parsed)) {+ return config.password || parsed.password;+ }return parsed.password;}diff --git a/packages/app-tests/connectionUrl.test.ts b/packages/app-tests/connectionUrl.test.tsindex 0913f4b626..f20b1f3358 100644--- a/packages/app-tests/connectionUrl.test.ts+++ b/packages/app-tests/connectionUrl.test.ts@@ -72,6 +72,57 @@ test("applies a credential-free KingBase URL without clearing typed credentials"assert.equal(applied.password, "typed-secret");});+test("applies a credential-free URL without clearing same-profile typed credentials", () => {+ const parsed = parseConnectionUrl("postgresql://db.example.com:5433/app?sslmode=require");+ const applied = applyParsedConnectionUrl({ name: "app", db_type: "postgres", username: "typed-user", password: "typed-secret" } as any, parsed);++ assert.equal(applied.host, "db.example.com");+ assert.equal(applied.port, 5433);+ assert.equal(applied.database, "app");+ assert.equal(applied.url_params, "sslmode=require");+ assert.equal(applied.ssl, true);+ assert.equal(applied.username, "typed-user");+ assert.equal(applied.password, "typed-secret");+});++test("uses explicit URL credentials instead of same-profile typed credentials", () => {+ const parsed = parseConnectionUrl("postgresql://url%40user:url%[email protected]/app");+ const applied = applyParsedConnectionUrl({ name: "app", db_type: "postgres", username: "typed-user", password: "typed-secret" } as any, parsed);++ assert.equal(applied.username, "url@user");+ assert.equal(applied.password, "url@secret");+});++test("does not carry typed credentials to a different URL profile", () => {+ const parsed = parseConnectionUrl("postgresql://db.example.com/app");+ const applied = applyParsedConnectionUrl({ name: "app", db_type: "mysql", username: "mysql-user", password: "mysql-secret" } as any, parsed);++ assert.equal(applied.db_type, "postgres");+ assert.equal(applied.username, "");+ assert.equal(applied.password, "");+});++test("does not carry typed credentials between driver profiles of the same database type", () => {+ const parsed = parseConnectionUrl("mariadb://db.example.com/app");+ const applied = applyParsedConnectionUrl(+ { name: "app", db_type: "mysql", driver_profile: "mysql", username: "mysql-user", password: "mysql-secret" } as any,+ parsed,+ );++ assert.equal(applied.db_type, "mysql");+ assert.equal(applied.driver_profile, "mariadb");+ assert.equal(applied.username, "");+ assert.equal(applied.password, "");+});++test("keeps empty same-profile form credentials empty for a credential-free URL", () => {+ const parsed = parseConnectionUrl("postgresql://db.example.com/app");+ const applied = applyParsedConnectionUrl({ name: "app", db_type: "postgres", username: "", password: "" } as any, parsed);++ assert.equal(applied.username, "");+ assert.equal(applied.password, "");+});+test("parses mysql URLs with encoded credentials", () => {const parsed = parseConnectionUrl("mysql://root:p%[email protected]/shop?charset=utf8mb4");