fix(telegram): keep draft preview chunks surrogate-safe · openclaw/openclaw@4bd68ae
mushuiyu886
·
2026-06-26
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -819,6 +819,20 @@ describe("createTelegramDraftStream", () => {
|
819 | 819 | expect(stream.lastDeliveredText?.()).toBe("1234567890"); |
820 | 820 | }); |
821 | 821 | |
| 822 | +it("does not split surrogate pairs when clamping a first oversized non-final preview", async () => { |
| 823 | +const api = createMockDraftApi(); |
| 824 | +const stream = createDraftStream(api, { maxChars: 10 }); |
| 825 | + |
| 826 | +stream.update("123456789😀tail"); |
| 827 | +await stream.flush(); |
| 828 | + |
| 829 | +expect(api.sendMessage).toHaveBeenCalledTimes(1); |
| 830 | +const sentText = requireSendMessageCallText(api, 0); |
| 831 | +expect(sentText).toBe("123456789"); |
| 832 | +expect(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/.test(sentText)).toBe(false); |
| 833 | +expect(stream.lastDeliveredText?.()).toBe("123456789"); |
| 834 | +}); |
| 835 | + |
822 | 836 | it("finalizes overflow that was hidden by a clamped non-final preview", async () => { |
823 | 837 | const api = createMockDraftApi(); |
824 | 838 | api.sendMessage |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import {
|
5 | 5 | takeMessageIdAfterStop, |
6 | 6 | } from "openclaw/plugin-sdk/channel-outbound"; |
7 | 7 | import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; |
| 8 | +import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; |
8 | 9 | import { buildTelegramThreadParams, type TelegramThreadSpec } from "./bot/helpers.js"; |
9 | 10 | import { renderTelegramHtmlText, telegramHtmlToPlainTextFallback } from "./format.js"; |
10 | 11 | import { |
@@ -169,7 +170,7 @@ function findTelegramDraftChunkLength(
|
169 | 170 | high = mid - 1; |
170 | 171 | } |
171 | 172 | } |
172 | | -return best; |
| 173 | +return sliceUtf16Safe(text, 0, best).length; |
173 | 174 | } |
174 | 175 | |
175 | 176 | export function createTelegramDraftStream(params: { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。