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(grid): copy text like mysql blobs as decoded text
ordinary being13fd1003f155
diff --git a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.tsindex d21e67ad45..0c038ae6fe 100644--- a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts@@ -2841,3 +2841,61 @@ describe("useDataGridExport VARBINARY 文本复制 (#7471)", () => {]);});});++// issue #12413:MySQL BLOB 列在网格里已经以文本预览显示(AES_DECRYPT 这类表达式的+// 结果列常被报成 BLOB),复制单元格/复制行/复制全部必须还原成同一份文本,否则用户看到+// `secret` 却粘贴出 hex。不可严格解码的 bytes 仍保持 hex,非 MySQL 的二进制列不受影响。+describe("useDataGridExport MySQL BLOB 文本复制 (#12413)", () => {+ const blobTable: DataGridTableMeta = {+ tableName: "test_blob",+ primaryKeys: ["id"],+ columns: [+ { name: "id", data_type: "int", is_nullable: false, is_primary_key: true },+ { name: "secret", data_type: "blob", is_nullable: false },+ ],+ };++ beforeEach(() => {+ vi.clearAllMocks();+ clearDataGridClipboardCopy();+ });++ it("复制文本型 BLOB 单元格时把 0x<hex> 还原为原始字符串", async () => {+ const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["secret"], rows: [["0x616263"]] };+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "abc", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });+ const state = createExportState(blobTable, ["id", "secret"], matrix, [1, "0x616263"]);++ await expect(state.copyWithPreference("smart")).resolves.toBe(true);++ expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ extractor: "raw", rows: [["abc"]] }));+ expect(copyToClipboard).toHaveBeenCalledWith("abc");+ // OS 剪贴板是文本,DBX 内部剪贴板仍保留原 hex,粘回 BLOB 时不重编码、不丢字节。+ expect(parseDataGridClipboard("abc")).toEqual([["0x616263"]]);+ });++ it("右键「复制单元格」对文本型 BLOB 直接写入原始字符串", async () => {+ const state = createExportState(blobTable, ["id", "secret"], undefined, [1, "0x616263"], undefined, undefined, [], DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, false, undefined, false, 1, 1);++ await state.copyCell();++ expect(copyToClipboard).toHaveBeenCalledWith("abc");+ });++ it("不可解码的 BLOB 保持 hex,非 MySQL 的二进制列不受影响", async () => {+ const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["secret"], rows: [["0x00fffe"]] };+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "0x00fffe", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });+ const state = createExportState(blobTable, ["id", "secret"], matrix, [1, "0x00fffe"]);++ await expect(state.copyWithPreference("smart")).resolves.toBe(true);++ expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ extractor: "raw", rows: [["0x00fffe"]] }));++ const textMatrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["secret"], rows: [["0x616263"]] };+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "0x616263", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });+ const sqliteState = createExportState(blobTable, ["id", "secret"], textMatrix, [1, "0x616263"], undefined, undefined, [], DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, false, undefined, false, 1, 1, "sqlite");++ await expect(sqliteState.copyWithPreference("smart")).resolves.toBe(true);++ expect(extractDataGridSelection).toHaveBeenLastCalledWith(expect.objectContaining({ extractor: "raw", rows: [["0x616263"]] }));+ });+});diff --git a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts b/apps/desktop/src/lib/dataGrid/binaryCellDownload.tsindex 34d7a77e3b..6593d326cd 100644--- a/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts+++ b/apps/desktop/src/lib/dataGrid/binaryCellDownload.ts@@ -291,7 +291,13 @@ export function binaryCellTextPreview(value: unknown, encoding: BinaryCellTextEn// VARBINARY,避免改变 MySQL BINARY/BLOB、SQL Server VARBINARY、PostgreSQL BYTEA、// Oracle RAW 等现有语义。export function binaryCellClipboardText(value: unknown, columnType?: string, databaseType?: DatabaseType): string | null {- if (databaseType !== "mysql" || !VARBINARY_TYPE_RE.test((columnType ?? "").trim())) return null;+ // 覆盖上方注释里「严格限于 VARBINARY」的旧范围(#12413):网格已经对文本型 MySQL+ // BLOB 显示文本预览(AES_DECRYPT 这类表达式的结果列常报成 BLOB),显示 `secret`+ // 却复制出 hex 与预览自相矛盾,因此 BLOB 家族并入同一闸门;严格往返校验与 hex+ // 回退保持不变,MySQL BINARY、非 MySQL 的 blob/bytea 等现有语义不受影响。+ const blobColumn = isBlobCellColumnType(columnType);+ const decodableType = VARBINARY_TYPE_RE.test((columnType ?? "").trim()) || blobColumn;+ if (databaseType !== "mysql" || !decodableType) return null;// MySQL QueryResult 的 binary canonical form 是 `0x<hex>`;不要把普通的偶数长度// 文本(例如 "abcd")猜测成 hex bytes。const bytes = typeof value === "string" ? parseBinaryCellHexValue(value) : null;@@ -303,6 +309,8 @@ export function binaryCellClipboardText(value: unknown, columnType?: string, dat// 与 GBK 回退无关,沿用 hex。return encoded.length === bytes.length && encoded.every((byte, index) => byte === bytes[index]) ? text : null;}+ // BLOB 家族与显示/编辑路径共用同一闸门:只解严格 UTF-8,不参与 GBK 回退。+ if (blobColumn) return null;return printableGbkText(binaryPreviewBytes(bytes, columnType));}diff --git a/packages/app-tests/binaryCellDownload.test.ts b/packages/app-tests/binaryCellDownload.test.tsindex 5ee03e96bf..99057a82cb 100644--- a/packages/app-tests/binaryCellDownload.test.ts+++ b/packages/app-tests/binaryCellDownload.test.ts@@ -235,8 +235,11 @@ test("binaryCellClipboardText decodes textual MySQL varbinary and preserves arbiassert.equal(binaryCellClipboardText(null, "VARBINARY(128)", "mysql"), null);// Case 7: 非目标类型 / 非 MySQL 一律不改写,回归保护。- assert.equal(binaryCellClipboardText("0x616263", "BLOB", "mysql"), null); // MySQL BLOB 不跟随- assert.equal(binaryCellClipboardText("0x616263", "LONGBLOB", "mysql"), null);+ // MySQL BLOB 跟随(#12413):网格对文本型 BLOB 显示文本预览,复制必须与显示一致;+ // BLOB 与显示/编辑路径一样只解严格 UTF-8,不做 GBK 回退。+ assert.equal(binaryCellClipboardText("0x616263", "BLOB", "mysql"), "abc");+ assert.equal(binaryCellClipboardText("0x616263", "LONGBLOB", "mysql"), "abc");+ assert.equal(binaryCellClipboardText("0xd6d0cec4", "LONGBLOB", "mysql"), null); // BLOB 不回退 GBK(与显示一致)assert.equal(binaryCellClipboardText("0x616263", "BINARY(8)", "mysql"), null); // MySQL BINARY 不跟随assert.equal(binaryCellClipboardText("0x616263", "VARBINARY(128)", "sqlserver"), null); // SQL Server varbinary 不改assert.equal(binaryCellClipboardText("0x616263", "bytea", "postgres"), null); // Postgres bytea 不改