From d63389ccf65bbd2e560f3163711e0979ddd1cdcd Mon Sep 17 00:00:00 2001 From: ly-wang19 <94427531+ly-wang19@users.noreply.github.com> Date: Tue, 23 Jun 2026 02:27:01 +0800 Subject: [PATCH] fix(qqbot): recognize GFM table separators with one or two dashes (#95637) `isTableSeparatorLine` required 3+ dashes per cell (`/^:?-{3,}:?$/`), but a GFM delimiter cell needs only one or more dashes. So a valid table whose separator used 1 or 2 dashes (e.g. `|--|--|`) was not recognized: the header stayed pending and was silently overwritten by each following row, so the table's header, separator, and every row but the last vanished from the sent message. Accept `-+` so valid GFM separators are recognized, matching the spec and the sibling LINE channel. Every existing test separator already uses 3+ dashes, so they are byte-identical. Co-authored-by: ly-wang19 Co-authored-by: Claude Opus 4.8 (1M context) --- .../src/engine/messaging/markdown-table-chunking.test.ts | 9 +++++++++ .../src/engine/messaging/markdown-table-chunking.ts | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/qqbot/src/engine/messaging/markdown-table-chunking.test.ts b/extensions/qqbot/src/engine/messaging/markdown-table-chunking.test.ts index 0a56bb33530..a516c635b91 100644 --- a/extensions/qqbot/src/engine/messaging/markdown-table-chunking.test.ts +++ b/extensions/qqbot/src/engine/messaging/markdown-table-chunking.test.ts @@ -46,6 +46,15 @@ describe("chunkQQBotMarkdownText", () => { ).toEqual([["| Id | Value |", "|---:|---|", "| 1 | alpha |", "| 2 | beta |"].join("\n")]); }); + it("confirms a table when the separator uses one or two dashes, not only three", () => { + // GFM delimiter cells need only one or more dashes; a sub-3-dash separator previously failed + // recognition, so the header and all rows but the last were silently dropped on send. + for (const separator of ["|--|--|", "|-|-|", "|:--|--:|"]) { + const text = ["| Id | Value |", separator, "| 1 | alpha |", "| 2 | beta |"].join("\n"); + expect(chunkQQBotMarkdownText(text, 200, baseChunker)).toEqual([text]); + } + }); + it("flushes a possible table header as text when the next block is not a separator", () => { const chunker = createQQBotMarkdownChunker((text) => [text]); diff --git a/extensions/qqbot/src/engine/messaging/markdown-table-chunking.ts b/extensions/qqbot/src/engine/messaging/markdown-table-chunking.ts index 343032415c2..0695f7c8e3a 100644 --- a/extensions/qqbot/src/engine/messaging/markdown-table-chunking.ts +++ b/extensions/qqbot/src/engine/messaging/markdown-table-chunking.ts @@ -433,7 +433,10 @@ function isTableSeparatorLine(line: string): boolean { return false; } const cells = splitTableCells(line); - return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell.trim())); + // GFM delimiter cells need only one or more hyphens (optionally colon-aligned), so accept "-+", + // not "-{3,}": a valid 1/2-dash separator (e.g. |--|--|) was not recognized here, leaving the + // header pending and silently overwritten by later rows so the table's header and rows vanished. + return cells.length > 0 && cells.every((cell) => /^:?-+:?$/.test(cell.trim())); } function splitTableCells(line: string): string[] {