Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pm-stack/aggregator/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,16 @@ const SESSION_SOURCES = new Set(["opencode-sandbox", "opencode-laptop", "claude-
function cleanText(v: unknown, max: number): string | undefined {
if (typeof v !== "string") return undefined;
const t = v.trim();
return t === "" ? undefined : t.slice(0, max);
if (t === "") return undefined;
if (t.length <= max) return t;
// Keep the UTF-16 cap, but never leave half of a surrogate pair at the
// cut (#7694, mirroring the #3178 guard in pm-dispatch validate.ts):
// an astral character straddling the cap is dropped whole.
let end = max;
const before = t.charCodeAt(end - 1);
const after = t.charCodeAt(end);
if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) end--;
return t.slice(0, end);
}

/** Validate an untrusted POST body into a NewAction, or explain why not. */
Expand Down
38 changes: 38 additions & 0 deletions pm-stack/aggregator/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,44 @@ describe("dashboard actions validation", () => {
expect(v({ objectRef: "has space" }).ok).toBe(false);
});

test("caps never split a surrogate pair (#7694)", () => {
// reason cap 2000: 1999 units + an astral character straddling the cap.
const straddle = validateNewAction({
...base,
verb: "dismiss",
payload: { reason: "x".repeat(1999) + "\u{1F600}" + "tail" },
});
expect(straddle.ok).toBe(true);
if (straddle.ok) {
const reason = (straddle.value.payload as { reason?: string }).reason ?? "";
expect(reason.length).toBe(1999);
expect(reason.endsWith("x")).toBe(true);
}
// A pair that fits exactly inside the cap is kept whole.
const fits = validateNewAction({
...base,
verb: "dismiss",
payload: { reason: "x".repeat(1998) + "\u{1F600}" },
});
expect(fits.ok).toBe(true);
if (fits.ok) {
const reason = (fits.value.payload as { reason?: string }).reason ?? "";
expect(reason.length).toBe(2000);
expect(reason.endsWith("\u{1F600}")).toBe(true);
}
// Small cap, same rule: optionId cap 200.
const opt = validateNewAction({
...base,
verb: "answer",
payload: { optionId: "o".repeat(199) + "\u{1F600}" + "tail" },
});
expect(opt.ok).toBe(true);
if (opt.ok) {
const optionId = (opt.value.payload as { optionId?: string }).optionId ?? "";
expect(optionId.length).toBe(199);
}
});

test("status-request: gh object, status required, targetRef derived", () => {
const ok = validateNewAction({
clientToken: "ct-valid-token-2",
Expand Down
Loading