openclaw/src/auto-reply/reply/inbound-text.test.ts
Marcus Castro d91e995e46
fix(inbound): preserve literal backslash-n sequences in Windows paths (#11547)
* fix(inbound): preserve literal backslash-n sequences in Windows paths

The normalizeInboundTextNewlines function was converting literal backslash-n
sequences (\n) to actual newlines, corrupting Windows paths like
C:\Work\nxxx\README.md when sent through WebUI.

This fix removes the .replaceAll("\\n", "\n") operation, preserving
literal backslash-n sequences while still normalizing actual CRLF/CR to LF.

Fixes #7968

* fix(test): set RawBody to Windows path so BodyForAgent fallback chain tests correctly

* fix: tighten Windows path newline regression coverage (#11547) (thanks @mcaxtr)

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-02-13 18:24:01 +01:00

36 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeInboundTextNewlines } from "./inbound-text.js";
describe("normalizeInboundTextNewlines", () => {
it("converts CRLF to LF", () => {
expect(normalizeInboundTextNewlines("hello\r\nworld")).toBe("hello\nworld");
});
it("converts CR to LF", () => {
expect(normalizeInboundTextNewlines("hello\rworld")).toBe("hello\nworld");
});
it("preserves literal backslash-n sequences in Windows paths", () => {
// Windows paths like C:\Work\nxxx should NOT have \n converted to newlines
const windowsPath = "C:\\Work\\nxxx\\README.md";
expect(normalizeInboundTextNewlines(windowsPath)).toBe("C:\\Work\\nxxx\\README.md");
});
it("preserves backslash-n in messages containing Windows paths", () => {
const message = "Please read the file at C:\\Work\\nxxx\\README.md";
expect(normalizeInboundTextNewlines(message)).toBe(
"Please read the file at C:\\Work\\nxxx\\README.md",
);
});
it("preserves multiple backslash-n sequences", () => {
const message = "C:\\new\\notes\\nested";
expect(normalizeInboundTextNewlines(message)).toBe("C:\\new\\notes\\nested");
});
it("still normalizes actual CRLF while preserving backslash-n", () => {
const message = "Line 1\r\nC:\\Work\\nxxx";
expect(normalizeInboundTextNewlines(message)).toBe("Line 1\nC:\\Work\\nxxx");
});
});