mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:21:23 +00:00
fix: strip leading whitespace from sanitizeUserFacingText output (#16158)
* fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as #8052 and #10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> --------- Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -69,4 +69,25 @@ describe("sanitizeUserFacingText", () => {
|
||||
const text = "Hello there!\n\nDifferent line.";
|
||||
expect(sanitizeUserFacingText(text)).toBe(text);
|
||||
});
|
||||
|
||||
it("strips leading newlines from LLM output", () => {
|
||||
expect(sanitizeUserFacingText("\n\nHello there!")).toBe("Hello there!");
|
||||
expect(sanitizeUserFacingText("\nHello there!")).toBe("Hello there!");
|
||||
expect(sanitizeUserFacingText("\n\n\nMultiple newlines")).toBe("Multiple newlines");
|
||||
});
|
||||
|
||||
it("strips leading whitespace and newlines combined", () => {
|
||||
expect(sanitizeUserFacingText("\n \n Hello")).toBe("Hello");
|
||||
expect(sanitizeUserFacingText(" \n\nHello")).toBe("Hello");
|
||||
});
|
||||
|
||||
it("preserves trailing whitespace and internal newlines", () => {
|
||||
expect(sanitizeUserFacingText("Hello\n\nWorld\n")).toBe("Hello\n\nWorld\n");
|
||||
expect(sanitizeUserFacingText("Line 1\nLine 2")).toBe("Line 1\nLine 2");
|
||||
});
|
||||
|
||||
it("returns empty for whitespace-only input", () => {
|
||||
expect(sanitizeUserFacingText("\n\n")).toBe("");
|
||||
expect(sanitizeUserFacingText(" \n ")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user