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>
This commit is contained in:
Marcus Castro
2026-02-13 14:24:01 -03:00
committed by GitHub
parent 684578ecf6
commit d91e995e46
4 changed files with 61 additions and 5 deletions

View File

@@ -61,16 +61,19 @@ describe("normalizeInboundTextNewlines", () => {
expect(normalizeInboundTextNewlines("a\rb")).toBe("a\nb");
});
it("decodes literal \\n to newlines when no real newlines exist", () => {
expect(normalizeInboundTextNewlines("a\\nb")).toBe("a\nb");
it("preserves literal backslash-n sequences (Windows paths)", () => {
// Windows paths like C:\Work\nxxx should NOT have \n converted to newlines
expect(normalizeInboundTextNewlines("a\\nb")).toBe("a\\nb");
expect(normalizeInboundTextNewlines("C:\\Work\\nxxx")).toBe("C:\\Work\\nxxx");
});
});
describe("finalizeInboundContext", () => {
it("fills BodyForAgent/BodyForCommands and normalizes newlines", () => {
const ctx: MsgContext = {
Body: "a\\nb\r\nc",
RawBody: "raw\\nline",
// Use actual CRLF for newline normalization test, not literal \n sequences
Body: "a\r\nb\r\nc",
RawBody: "raw\r\nline",
ChatType: "channel",
From: "whatsapp:group:123@g.us",
GroupSubject: "Test",
@@ -87,6 +90,20 @@ describe("finalizeInboundContext", () => {
expect(out.ConversationLabel).toContain("Test");
});
it("preserves literal backslash-n in Windows paths", () => {
const ctx: MsgContext = {
Body: "C:\\Work\\nxxx\\README.md",
RawBody: "C:\\Work\\nxxx\\README.md",
ChatType: "direct",
From: "web:user",
};
const out = finalizeInboundContext(ctx);
expect(out.Body).toBe("C:\\Work\\nxxx\\README.md");
expect(out.BodyForAgent).toBe("C:\\Work\\nxxx\\README.md");
expect(out.BodyForCommands).toBe("C:\\Work\\nxxx\\README.md");
});
it("can force BodyForCommands to follow updated CommandBody", () => {
const ctx: MsgContext = {
Body: "base",