mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 09:31:25 +00:00
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:
35
src/auto-reply/reply/inbound-text.test.ts
Normal file
35
src/auto-reply/reply/inbound-text.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,6 @@
|
||||
export function normalizeInboundTextNewlines(input: string): string {
|
||||
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll("\\n", "\n");
|
||||
// Normalize actual newline characters (CR+LF and CR to LF).
|
||||
// Do NOT replace literal backslash-n sequences (\\n) as they may be part of
|
||||
// Windows paths like C:\Work\nxxx\README.md or user-intended escape sequences.
|
||||
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user