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): copy raw password from the edit dialog field
zipg3da94ca069a4
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vueindex e428161af8..bbea1cf93d 100644--- a/apps/desktop/src/components/connection/ConnectionDialog.vue+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue@@ -103,7 +103,7 @@ import { consulAgentAddressesMatch } from "@/lib/consul/agentTarget";import { appendConnectionErrorHints, isJdbcMissingRuntimeDependencyError } from "@/lib/connection/connectionErrorHints";import { buildCassandraExternalConfig, cassandraTlsConfigFromExternalConfig, type CassandraTlsConfig } from "@/lib/connection/cassandraTlsOptions";import { savedMysqlTlsFormFields, supportsMysqlTlsOptions as mysqlTlsOptionsSupported, supportsMysqlTlsTab } from "@/lib/connection/mysqlTlsCapabilities";-import { preventDialogDocumentSelectAll } from "@/lib/connection/dialogTextSelection";+import { copyDialogPasswordFieldValue, preventDialogDocumentSelectAll } from "@/lib/connection/dialogTextSelection";import { postgresLegacyTlsEnabled, postgresTlsModeForForm, setPostgresLegacyTlsEnabled } from "@/lib/connection/postgresTlsMode";import { buildMqKafkaConnectionExtra, mqKafkaConnectionTarget, resolveMqKafkaConnectionSource, type MqKafkaConnectionSource } from "@/lib/connection/mqKafkaConnection";import { assertCompleteDatabaseCategories, databaseSelectionForCategory } from "@/lib/connection/databaseCategoryOptions";@@ -6832,7 +6832,16 @@ function openExternalUrl(url: string) {<template><Dialog v-model:open="open">- <DialogContent :style="dialogContentStyle" class="connection-dialog-content" :class="connectionDialogContentClass" :data-wide="shouldUseWideConnectionDialog ? 'true' : undefined" @interact-outside.prevent @escape-key-down="handleDialogEscape" @keydown="preventDialogDocumentSelectAll">+ <DialogContent+ :style="dialogContentStyle"+ class="connection-dialog-content"+ :class="connectionDialogContentClass"+ :data-wide="shouldUseWideConnectionDialog ? 'true' : undefined"+ @interact-outside.prevent+ @escape-key-down="handleDialogEscape"+ @keydown="preventDialogDocumentSelectAll"+ @copy="copyDialogPasswordFieldValue"+ ><DialogHeader class="cursor-move select-none" @pointerdown="onDialogHeaderPointerDown" @pointermove="onDialogHeaderPointerMove" @pointerup="onDialogHeaderPointerEnd" @pointercancel="onDialogHeaderPointerEnd"><DialogTitle>{{ editingId ? t("connection.editTitle") : t("connection.title") }}</DialogTitle></DialogHeader>diff --git a/apps/desktop/src/components/ui/PasswordInput.vue b/apps/desktop/src/components/ui/PasswordInput.vueindex 23fc155dbd..7d161fbc90 100644--- a/apps/desktop/src/components/ui/PasswordInput.vue+++ b/apps/desktop/src/components/ui/PasswordInput.vue@@ -31,7 +31,7 @@ const toggleLabel = computed(() => (visible.value ? props.hideLabel || t("common<template><div :class="props.class" class="relative">- <Input v-model="model" :type="visible ? 'text' : 'password'" :placeholder="placeholder" :disabled="disabled" :class="[props.inputClass, props.showToggle ? 'pr-8' : undefined]" v-bind="$attrs" />+ <Input v-model="model" data-password-input :type="visible ? 'text' : 'password'" :placeholder="placeholder" :disabled="disabled" :class="[props.inputClass, props.showToggle ? 'pr-8' : undefined]" v-bind="$attrs" /><buttonv-if="props.showToggle"type="button"diff --git a/apps/desktop/src/components/ui/__tests__/PasswordInput.spec.ts b/apps/desktop/src/components/ui/__tests__/PasswordInput.spec.tsnew file mode 100644index 0000000000..5cd309e08f--- /dev/null+++ b/apps/desktop/src/components/ui/__tests__/PasswordInput.spec.ts@@ -0,0 +1,39 @@+// @vitest-environment happy-dom++import { createApp, nextTick } from "vue";+import { createI18n } from "vue-i18n";+import { afterEach, describe, expect, it } from "vitest";+import PasswordInput from "@/components/ui/PasswordInput.vue";++const mountedContainers: HTMLDivElement[] = [];++async function mountPasswordInput(value: string) {+ const container = document.createElement("div");+ mountedContainers.push(container);+ document.body.append(container);++ const app = createApp(PasswordInput, { modelValue: value });+ app.use(createI18n({ legacy: false, locale: "en", messages: { en: { common: { showPassword: "Show password", hidePassword: "Hide password" } } } }));+ app.mount(container);+ await nextTick();+ return container;+}++afterEach(() => {+ while (mountedContainers.length > 0) mountedContainers.pop()?.remove();+});++describe("PasswordInput", () => {+ it("marks the field so dialogs can copy the raw value when revealed", async () => {+ const container = await mountPasswordInput("p^ss%40@x#y");+ const input = container.querySelector<HTMLInputElement>("input[data-password-input]");++ expect(input).not.toBeNull();+ expect(input?.value).toBe("p^ss%40@x#y");+ expect(input?.getAttribute("type")).toBe("password");++ container.querySelector<HTMLButtonElement>("button")?.click();+ await nextTick();+ expect(container.querySelector<HTMLInputElement>("input[data-password-input]")?.getAttribute("type")).toBe("text");+ });+});diff --git a/apps/desktop/src/lib/connection/__tests__/dialogTextSelection.spec.ts b/apps/desktop/src/lib/connection/__tests__/dialogTextSelection.spec.tsindex cc6e659816..e4fa861b3d 100644--- a/apps/desktop/src/lib/connection/__tests__/dialogTextSelection.spec.ts+++ b/apps/desktop/src/lib/connection/__tests__/dialogTextSelection.spec.ts@@ -1,7 +1,7 @@// @vitest-environment happy-domimport { describe, expect, it, vi } from "vitest";-import { preventDialogDocumentSelectAll } from "../dialogTextSelection";+import { copyDialogPasswordFieldValue, preventDialogDocumentSelectAll } from "../dialogTextSelection";function keyboardEvent(target: EventTarget, options: { key?: string; metaKey?: boolean; ctrlKey?: boolean; altKey?: boolean } = {}) {return {@@ -47,3 +47,60 @@ describe("preventDialogDocumentSelectAll", () => {expect(event.preventDefault).not.toHaveBeenCalled();});});++function clipboardEvent(target: EventTarget) {+ return {+ target,+ preventDefault: vi.fn(),+ clipboardData: { setData: vi.fn() },+ } as unknown as ClipboardEvent;+}++function passwordInput(value: string, options: { masked?: boolean; marker?: boolean; selection?: [number, number] } = {}) {+ const input = document.createElement("input");+ input.type = options.masked === false ? "text" : "password";+ if (options.marker !== false) input.setAttribute("data-password-input", "");+ input.value = value;+ const [start, end] = options.selection ?? [value.length, value.length];+ input.setSelectionRange(start, end);+ return input;+}++describe("copyDialogPasswordFieldValue", () => {+ it("copies the whole revealed password when only the caret sits in the field", () => {+ const input = passwordInput("p^ss%40@x#y", { masked: false });+ const event = clipboardEvent(input);++ expect(copyDialogPasswordFieldValue(event)).toBe(true);+ expect(event.preventDefault).toHaveBeenCalledOnce();+ expect((event.clipboardData as unknown as { setData: ReturnType<typeof vi.fn> }).setData).toHaveBeenCalledWith("text/plain", "p^ss%40@x#y");+ });++ it("copies the whole password while the field is still masked", () => {+ const input = passwordInput("p^ss%40@x#y", { masked: true });+ const event = clipboardEvent(input);++ expect(copyDialogPasswordFieldValue(event)).toBe(true);+ expect(event.preventDefault).toHaveBeenCalledOnce();+ });++ it("keeps the native substring copy when text is selected", () => {+ const input = passwordInput("p^ss%40@x#y", { masked: false, selection: [0, 4] });+ const event = clipboardEvent(input);++ expect(copyDialogPasswordFieldValue(event)).toBe(false);+ expect(event.preventDefault).not.toHaveBeenCalled();+ });++ it("leaves other inputs and empty passwords alone", () => {+ const plain = passwordInput("app_user", { masked: false, marker: false });+ const plainEvent = clipboardEvent(plain);+ const empty = passwordInput("", { masked: false });+ const emptyEvent = clipboardEvent(empty);++ expect(copyDialogPasswordFieldValue(plainEvent)).toBe(false);+ expect(copyDialogPasswordFieldValue(emptyEvent)).toBe(false);+ expect(plainEvent.preventDefault).not.toHaveBeenCalled();+ expect(emptyEvent.preventDefault).not.toHaveBeenCalled();+ });+});diff --git a/apps/desktop/src/lib/connection/dialogTextSelection.ts b/apps/desktop/src/lib/connection/dialogTextSelection.tsindex 18c9556b01..0b18e1fe83 100644--- a/apps/desktop/src/lib/connection/dialogTextSelection.ts+++ b/apps/desktop/src/lib/connection/dialogTextSelection.ts@@ -9,3 +9,33 @@ export function preventDialogDocumentSelectAll(event: KeyboardEvent): boolean {event.preventDefault();return true;}++function isPasswordFieldTarget(target: EventTarget | null): target is HTMLInputElement {+ if (!(target instanceof HTMLInputElement)) return false;+ // A revealed password is a plain text input, so the reveal toggle marks it+ // explicitly; a masked one is recognizable from its type alone.+ return target.type === "password" || target.hasAttribute("data-password-input");+}++/**+ * Copy the whole password value when a copy shortcut runs without a selection.+ *+ * A password input only copies its selection, so pressing Ctrl/Cmd+C with just+ * a caret writes nothing and leaves the previous clipboard content in place.+ * Users who reveal a stored password and copy it that way would then paste+ * whatever they copied earlier - typically the percent-encoded connection URL -+ * which looks like the password itself was escaped. Writing the field value+ * keeps the clipboard identical to what the field shows; an explicit selection+ * still copies the native substring.+ */+export function copyDialogPasswordFieldValue(event: ClipboardEvent): boolean {+ const input = event.target;+ if (!isPasswordFieldTarget(input)) return false;+ if ((input.selectionStart ?? 0) !== (input.selectionEnd ?? 0)) return false;+ if (!input.value) return false;+ const clipboard = event.clipboardData;+ if (!clipboard) return false;+ event.preventDefault();+ clipboard.setData("text/plain", input.value);+ return true;+}