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 <ly-wang19@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
ly-wang19
2026-06-23 02:27:01 +08:00
committed by GitHub
parent 420a0e6fce
commit d63389ccf6
2 changed files with 13 additions and 1 deletions

View File

@@ -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]);

View File

@@ -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[] {