mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 00:11:19 +00:00
fix(whatsapp): keep echo tracker log truncation UTF-16 safe (#102603)
* fix(whatsapp): keep echo tracker log truncation UTF-16 safe Replace `.slice(0, 50)` with `truncateUtf16Safe(text, 50)` in echo tracker verbose log message to prevent surrogate pair corruption. Ref. lsr911 pattern — mechanical substitution, no behavior change. * test(whatsapp): cover UTF-16-safe echo previews --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
parent
5154fe08fa
commit
0a8677ec99
2 changed files with 20 additions and 1 deletions
18
extensions/whatsapp/src/auto-reply/monitor/echo.test.ts
Normal file
18
extensions/whatsapp/src/auto-reply/monitor/echo.test.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createEchoTracker } from "./echo.js";
|
||||
|
||||
describe("createEchoTracker", () => {
|
||||
it("keeps verbose previews UTF-16 safe without changing the tracked text", () => {
|
||||
const logVerbose = vi.fn();
|
||||
const tracker = createEchoTracker({ logVerbose });
|
||||
const prefix = "x".repeat(49);
|
||||
const text = `${prefix}😀tail`;
|
||||
|
||||
tracker.rememberText(text, { logVerboseMessage: true });
|
||||
|
||||
expect(logVerbose).toHaveBeenCalledExactlyOnceWith(
|
||||
`Added to echo detection set (size now: 1): ${prefix}...`,
|
||||
);
|
||||
expect(tracker.has(text)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// Whatsapp plugin module implements echo behavior.
|
||||
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
||||
export type EchoTracker = {
|
||||
rememberText: (
|
||||
text: string | undefined,
|
||||
|
|
@ -48,7 +49,7 @@ export function createEchoTracker(params: {
|
|||
}
|
||||
if (opts.logVerboseMessage) {
|
||||
params.logVerbose?.(
|
||||
`Added to echo detection set (size now: ${recentlySent.size}): ${text.slice(0, 50)}...`,
|
||||
`Added to echo detection set (size now: ${recentlySent.size}): ${truncateUtf16Safe(text, 50)}...`,
|
||||
);
|
||||
}
|
||||
trim();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue