mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(telegram): keep draft preview chunks surrogate-safe
This commit is contained in:
committed by
Ayaan Zaidi
parent
8bc069f76f
commit
4bd68aef65
@@ -819,6 +819,20 @@ describe("createTelegramDraftStream", () => {
|
||||
expect(stream.lastDeliveredText?.()).toBe("1234567890");
|
||||
});
|
||||
|
||||
it("does not split surrogate pairs when clamping a first oversized non-final preview", async () => {
|
||||
const api = createMockDraftApi();
|
||||
const stream = createDraftStream(api, { maxChars: 10 });
|
||||
|
||||
stream.update("123456789😀tail");
|
||||
await stream.flush();
|
||||
|
||||
expect(api.sendMessage).toHaveBeenCalledTimes(1);
|
||||
const sentText = requireSendMessageCallText(api, 0);
|
||||
expect(sentText).toBe("123456789");
|
||||
expect(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/.test(sentText)).toBe(false);
|
||||
expect(stream.lastDeliveredText?.()).toBe("123456789");
|
||||
});
|
||||
|
||||
it("finalizes overflow that was hidden by a clamped non-final preview", async () => {
|
||||
const api = createMockDraftApi();
|
||||
api.sendMessage
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
takeMessageIdAfterStop,
|
||||
} from "openclaw/plugin-sdk/channel-outbound";
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
||||
import { buildTelegramThreadParams, type TelegramThreadSpec } from "./bot/helpers.js";
|
||||
import { renderTelegramHtmlText, telegramHtmlToPlainTextFallback } from "./format.js";
|
||||
import {
|
||||
@@ -169,7 +170,7 @@ function findTelegramDraftChunkLength(
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
return sliceUtf16Safe(text, 0, best).length;
|
||||
}
|
||||
|
||||
export function createTelegramDraftStream(params: {
|
||||
|
||||
Reference in New Issue
Block a user