Skip to content

Commit 1f40646

Browse files
fix(board): prevent emoji corruption in event notices (#111702)
* fix(board): preserve Unicode notice boundaries * test(board): document surrogate boundary * test(pr): isolate wrapper command inventory
1 parent 732c574 commit 1f40646

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎src/boards/board-notices.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
12
import { enqueueSystemEvent } from "../infra/system-events.js";
23

34
const BOARD_EVENT_MAX_BYTES = 8 * 1024;
@@ -27,7 +28,9 @@ function formatNotice(widget: string, summary: string): string {
2728
const suffix = ` on widget ${widget}`;
2829
const available = BOARD_NOTICE_MAX_CHARS - prefix.length - suffix.length;
2930
const clipped =
30-
summary.length <= available ? summary : `${summary.slice(0, Math.max(0, available - 1))}…`;
31+
summary.length <= available
32+
? summary
33+
: `${truncateUtf16Safe(summary, Math.max(0, available - 1))}…`;
3134
return `${prefix}${clipped}${suffix}`;
3235
}
3336

‎src/gateway/server-methods/board.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,27 @@ describe("board gateway methods", () => {
10081008
expect(triggerCronJob).toHaveBeenCalledWith("job-1", expect.any(Object));
10091009
});
10101010

1011-
it("caps board.event payloads at 8KB and notices at 500 characters", async () => {
1011+
it("caps board.event payloads and preserves Unicode at the notice boundary", async () => {
10121012
const { invoke } = createHarness();
10131013
await invoke("board.widget.put", {
10141014
sessionKey: "session",
10151015
name: "counter",
10161016
content: { kind: "html", html: "ok" },
10171017
});
1018+
const clippedCodeUnits = 500 - "[dashboard] ".length - " on widget counter".length - 1;
1019+
// JSON's opening quote places the emoji across the legacy slice boundary.
1020+
const payload = `${"x".repeat(clippedCodeUnits - 2)}😀tail`;
1021+
await invoke("board.event", { sessionKey: "session", widget: "counter", payload });
1022+
const unicodeNotice = peekSystemEvents("session")[0] ?? "";
1023+
expect(unicodeNotice.length).toBeLessThanOrEqual(500);
1024+
expect(unicodeNotice).not.toContain(String.fromCharCode(0xd83d));
1025+
expect(unicodeNotice).toMatch(/… on widget counter$/u);
10181026
await invoke("board.event", {
10191027
sessionKey: "session",
10201028
widget: "counter",
10211029
payload: "x".repeat(1_000),
10221030
});
1023-
expect(peekSystemEvents("session")[0]).toHaveLength(500);
1031+
expect(peekSystemEvents("session")[1]).toHaveLength(500);
10241032
const oversized = await invoke("board.event", {
10251033
sessionKey: "session",
10261034
widget: "counter",

‎test/scripts/pr-wrappers.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ function makeMismatchedWrapperRepo() {
3939
const originPath = join(root, "origin.git");
4040
mkdirSync(bin, { recursive: true });
4141
mkdirSync(home, { recursive: true });
42-
writeFileSync(join(bin, "rg"), "#!/usr/bin/env sh\nexit 0\n");
43-
chmodSync(join(bin, "rg"), 0o755);
42+
// This fixture exercises wrapper trust routing, not the host command inventory.
43+
for (const command of ["jq", "pnpm", "rg"]) {
44+
const commandPath = join(bin, command);
45+
writeFileSync(commandPath, "#!/bin/sh\nexit 0\n");
46+
chmodSync(commandPath, 0o755);
47+
}
4448

4549
const fixtureEnv = {
4650
...process.env,
@@ -186,6 +190,7 @@ describe("scripts/pr wrappers", () => {
186190
try {
187191
rmSync(join(fixture.bin, "rg"));
188192
for (const command of ["bash", "basename", "dirname", "git", "jq", "pnpm", "node"]) {
193+
rmSync(join(fixture.bin, command), { force: true });
189194
symlinkSync(resolveCommand(command), join(fixture.bin, command));
190195
}
191196

0 commit comments

Comments
 (0)