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): trim stray whitespace around host, username, and database (#12936)
imhyuk-huno8f9ad4f3561c
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vueindex a3a80040e5..6f72191377 100644--- a/apps/desktop/src/components/connection/ConnectionDialog.vue+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue@@ -4986,6 +4986,18 @@ function connectionConfigForSubmit(id: string, generatedName = "", validatePlugiconfig.host = serialized.host;config.port = serialized.port;}+ // Hostnames and usernames cannot contain leading/trailing whitespace, so a+ // stray space (typically from copy-pasting) can only be a mistake — but it+ // still reaches the driver and fails in a way the error message does not+ // make visible. Passwords are left untouched because surrounding spaces can+ // be significant, and file-path hosts (SQLite/DuckDB/H2 file mode) keep+ // their exact value for the same reason.+ const usesLocalFilePathHost = isLocalFileTypeDb(config.db_type) && (config.db_type !== "h2" || h2ConnectionModeForConfig(config) === "file");+ if (!usesLocalFilePathHost) {+ config.host = config.host.trim();+ }+ config.username = config.username.trim();+ config.database = config.database?.trim() || undefined;if (isCloudflareD1Connection(config)) {normalizeCloudflareD1Connection(config);if (!hasCloudflareD1Credentials(config)) {diff --git a/apps/desktop/src/components/connection/__tests__/ConnectionDialog.hostTrim.spec.ts b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.hostTrim.spec.tsnew file mode 100644index 0000000000..05a12bd3fb--- /dev/null+++ b/apps/desktop/src/components/connection/__tests__/ConnectionDialog.hostTrim.spec.ts@@ -0,0 +1,230 @@+// @vitest-environment happy-dom++import { createApp, defineComponent, h, nextTick, reactive, type App } from "vue";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import i18n from "@/i18n";+import type { ConnectionConfig } from "@/types/database";++const { store, settings, backend } = vi.hoisted(() => ({+ store: {+ connectionGroupOptions: [],+ newConnectionGroupId: null,+ selectedConnectionGroupId: null,+ addConnection: vi.fn(),+ updateConnection: vi.fn(),+ connect: vi.fn(),+ ensureConnected: vi.fn(),+ addEphemeralConnection: vi.fn(),+ removeConnection: vi.fn(),+ startEditing: vi.fn(),+ stopEditing: vi.fn(),+ clearConnectionError: vi.fn(),+ updateConnectionDatabaseInfo: vi.fn(),+ applyGlobalTimeouts: vi.fn((config) => config),+ getConfig: vi.fn(),+ },+ settings: {+ editorSettings: { sidebarShowConnectionNotes: false, globalConnectTimeoutSecs: 10, globalQueryTimeoutSecs: 0 },+ rememberedDatabaseForConnection: vi.fn(() => ""),+ persistEditorSettings: vi.fn(),+ updateEditorSettings: vi.fn(),+ updateEditorSettingsAndPersist: vi.fn(),+ },+ backend: {+ connectDb: vi.fn(),+ disconnectDb: vi.fn(),+ testConnectionWithInfo: vi.fn(),+ listDatabases: vi.fn(),+ listPlugins: vi.fn(),+ listJdbcDrivers: vi.fn(),+ listJdbcMavenBundles: vi.fn(),+ listJdbcLocalBundles: vi.fn(),+ listSshConfigHosts: vi.fn(),+ listInstalledAgentsLocal: vi.fn(),+ listenAgentInstallProgress: vi.fn(),+ },+}));++vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => store, CONNECTION_ATTEMPT_CANCELLED_MESSAGE: "cancelled" }));+vi.mock("@/stores/settingsStore", async (original) => ({ ...(await original<typeof import("@/stores/settingsStore")>()), useSettingsStore: () => settings }));+vi.mock("@/stores/tunnelProfileStore", () => ({ useTunnelProfileStore: () => ({ profiles: [], profileById: () => undefined, init: vi.fn() }) }));+vi.mock("@/lib/backend/api", async (original) => ({ ...(await original<typeof import("@/lib/backend/api")>()), ...backend }));+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));++vi.mock("@/components/ui/dialog", async () => {+ const { defineComponent, h } = await import("vue");+ const passthrough = defineComponent({+ setup:+ (_props, { slots }) =>+ () =>+ h("div", slots.default?.()),+ });+ const Dialog = defineComponent({+ props: { open: Boolean },+ emits: ["update:open"],+ setup:+ (props, { slots, emit }) =>+ () =>+ props.open ? h("section", [h("button", { "data-testid": "dismiss-dialog", onClick: () => emit("update:open", false) }, "Dismiss"), slots.default?.()]) : null,+ });+ return { Dialog, DialogContent: passthrough, DialogHeader: passthrough, DialogTitle: passthrough, DialogFooter: passthrough };+});+vi.mock("@/components/ui/button", async () => {+ const { defineComponent, h } = await import("vue");+ return {+ Button: defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("button", attrs, slots.default?.()),+ }),+ };+});+vi.mock("@/components/ui/tabs", async () => {+ const { defineComponent, h } = await import("vue");+ const pass = defineComponent({+ setup:+ (_props, { slots }) =>+ () =>+ h("div", slots.default?.()),+ });+ const TabsContent = defineComponent({+ props: { value: String },+ setup:+ (props, { slots }) =>+ () =>+ props.value === "connection" ? h("div", slots.default?.()) : null,+ });+ return { Tabs: pass, TabsContent, TabsList: pass, TabsTrigger: pass };+});+vi.mock("@/components/ui/tooltip", async () => {+ const { defineComponent, h } = await import("vue");+ const pass = defineComponent({+ setup:+ (_props, { slots }) =>+ () =>+ h("span", slots.default?.()),+ });+ return { HelpTooltip: pass, Tooltip: pass, TooltipContent: pass, TooltipTrigger: pass };+});++import ConnectionDialog from "@/components/connection/ConnectionDialog.vue";++const mountedApps: App[] = [];++async function settle() {+ for (let i = 0; i < 8; i++) await nextTick();+}++async function mountDialog(config: ConnectionConfig) {+ const props = reactive({ open: true, editConfig: config });+ store.getConfig.mockReturnValue(config);+ const container = document.createElement("div");+ document.body.append(container);+ const app = createApp(+ defineComponent({+ setup: () => () =>+ h(ConnectionDialog, {+ ...props,+ "onUpdate:open": (value: boolean) => {+ props.open = value;+ },+ }),+ }),+ );+ app.use(i18n);+ mountedApps.push(app);+ app.mount(container);+ await settle();+}++function inputByValue(value: string): HTMLInputElement | null {+ return [...document.querySelectorAll<HTMLInputElement>("input")].find((input) => input.value === value) ?? null;+}++function setInputValue(input: HTMLInputElement, value: string) {+ input.value = value;+ input.dispatchEvent(new Event("input"));+}++function saveButton(): HTMLButtonElement | null {+ return [...document.querySelectorAll<HTMLButtonElement>("button")].find((button) => button.textContent?.trim() === "Save") ?? null;+}++async function saveDialog() {+ saveButton()?.click();+ for (let i = 0; i < 12; i++) await nextTick();+}++beforeEach(() => {+ vi.clearAllMocks();+ i18n.global.locale.value = "en";+ for (const fn of Object.values(backend)) fn.mockResolvedValue([]);+ backend.listenAgentInstallProgress.mockResolvedValue(() => {});+ store.updateConnection.mockResolvedValue(undefined);+ store.addConnection.mockResolvedValue(undefined);+});++afterEach(() => {+ for (const app of mountedApps.splice(0)) app.unmount();+ document.body.innerHTML = "";+});++function postgresConnection(overrides: Partial<ConnectionConfig> = {}): ConnectionConfig {+ return {+ id: "pg-1",+ name: "PostgreSQL",+ db_type: "postgresql",+ host: "original.local",+ port: 5432,+ username: "dbx",+ password: "secret-pass",+ ...overrides,+ } as ConnectionConfig;+}++describe("ConnectionDialog whitespace trimming", () => {+ it("trims stray whitespace around host and username before saving", async () => {+ await mountDialog(postgresConnection());++ const hostInput = inputByValue("original.local");+ expect(hostInput, "host input should be rendered").toBeTruthy();+ setInputValue(hostInput!, " docker.for.mac.host.internal ");+ await settle();++ await saveDialog();++ expect(store.updateConnection).toHaveBeenCalledWith(expect.objectContaining({ host: "docker.for.mac.host.internal" }));+ });++ it("keeps the password untouched so surrounding spaces stay significant", async () => {+ await mountDialog(postgresConnection({ password: " padded secret " }));++ await saveDialog();++ expect(store.updateConnection).toHaveBeenCalledWith(expect.objectContaining({ password: " padded secret " }));+ });++ it("does not trim the host for file-path based connections", async () => {+ await mountDialog({+ id: "sqlite-1",+ name: "SQLite",+ db_type: "sqlite",+ host: "/tmp/original.db",+ port: 0,+ username: "",+ password: "",+ } as ConnectionConfig);++ const pathInput = inputByValue("/tmp/original.db");+ expect(pathInput, "file path input should be rendered").toBeTruthy();+ setInputValue(pathInput!, "/tmp/ spaced name.db ");+ await settle();++ await saveDialog();++ expect(store.updateConnection).toHaveBeenCalledWith(expect.objectContaining({ host: "/tmp/ spaced name.db " }));+ });+});