From 5acabfd897473c59d0e2f1af09dd74b6bfecb5b2 Mon Sep 17 00:00:00 2001 From: Super-Cabbage Date: Mon, 6 Jul 2026 16:00:08 +0800 Subject: [PATCH] fix(commands): guard shortenText against non-positive maxLen (#99917) * fix(commands): guard shortenText against non-positive maxLen * fix(commands): guard shortenText against non-positive maxLen --------- Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + src/commands/text-format.test.ts | 5 +++++ src/commands/text-format.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80707475723b..90cf23380de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- **Command output truncation:** return an empty string for non-positive shortening limits instead of emitting an over-budget ellipsis. (#99917) Thanks @Super-Cabbage. - **Agent helper downloads:** bound fd and ripgrep archive downloads and extraction with declared and streamed byte caps, extraction limits, timeouts, traversal-safe unpacking, and partial-file cleanup. (#98988) Thanks @LeonidasLux. - **Control UI cron actions:** localize the overflow-menu label and due-only run action across all supported locales. - **OpenRouter OAuth and Discord webhook response bounds:** cap successful JSON response bodies while preserving Discord's no-body webhook mode. (#98098) Thanks @lwy-2. diff --git a/src/commands/text-format.test.ts b/src/commands/text-format.test.ts index d0aa57566d47..96c1fe50a7f8 100644 --- a/src/commands/text-format.test.ts +++ b/src/commands/text-format.test.ts @@ -11,6 +11,11 @@ describe("shortenText", () => { expect(shortenText("openclaw-status-output", 10)).toBe("openclaw-…"); }); + it("returns an empty string for non-positive limits", () => { + expect(shortenText("openclaw", 0)).toBe(""); + expect(shortenText("openclaw", -1)).toBe(""); + }); + it("counts multi-byte characters correctly", () => { expect(shortenText("hello🙂world", 7)).toBe("hello🙂…"); }); diff --git a/src/commands/text-format.ts b/src/commands/text-format.ts index 9df8a4e8b7d8..851117e42a55 100644 --- a/src/commands/text-format.ts +++ b/src/commands/text-format.ts @@ -3,6 +3,9 @@ /** Shortens text to maxLen code points, appending an ellipsis when truncated. */ export const shortenText = (value: string, maxLen: number) => { + if (maxLen <= 0) { + return ""; + } const chars = Array.from(value); if (chars.length <= maxLen) { return value;