fix(line): preserve Unicode boundaries in recipient errors (#104109)

This commit is contained in:
mushuiyu886
2026-07-12 08:03:58 +08:00
committed by GitHub
parent 57c2d65ad5
commit d886059520
2 changed files with 19 additions and 1 deletions

View File

@@ -384,6 +384,24 @@ describe("LINE send helpers", () => {
expect(pushMessageMock).not.toHaveBeenCalled();
});
it("preserves UTF-16 boundaries in invalid recipient diagnostics", async () => {
await expect(
sendModule.pushMessagesLine(`aab😀${"x".repeat(40)}`, [{ type: "text", text: "hello" }], {
cfg: LINE_TEST_CFG,
}),
).rejects.toThrow(
"Recipient is not a valid LINE id (case-sensitive; expected leading capital C/U/R): aab…",
);
await expect(
sendModule.pushMessagesLine(`aa😀${"y".repeat(40)}`, [{ type: "text", text: "hello" }], {
cfg: LINE_TEST_CFG,
}),
).rejects.toThrow(
"Recipient is not a valid LINE id (case-sensitive; expected leading capital C/U/R): aa😀…",
);
expect(pushMessageMock).not.toHaveBeenCalled();
});
it("accepts case-exact LINE recipients with the leading capital preserved", async () => {
await sendModule.pushMessagesLine(
"Cabcdef0123456789abcdef0123456789",

View File

@@ -79,7 +79,7 @@ function normalizeTarget(to: string): string {
// fixtures (e.g. "U123") are left alone. openclaw/openclaw#81628
if (normalized.length >= 33 && !/^[CUR]/.test(normalized)) {
throw new Error(
`Recipient is not a valid LINE id (case-sensitive; expected leading capital C/U/R): ${normalized.slice(0, 4)}`,
`Recipient is not a valid LINE id (case-sensitive; expected leading capital C/U/R): ${truncateUtf16Safe(normalized, 4)}`,
);
}