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>
This commit is contained in:
Super-Cabbage
2026-07-06 16:00:08 +08:00
committed by GitHub
parent 3b189dfd34
commit 5acabfd897
3 changed files with 9 additions and 0 deletions
+1
View File
@@ -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.
+5
View File
@@ -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🙂…");
});
+3
View File
@@ -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;