Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/zee/Swabble/src/auto-reply/reply/inbound-text.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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", () => {
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 C:\\Work\\nxxx\\README.md";
expect(normalizeInboundTextNewlines(message)).toBe("Please read C:\\Work\\nxxx\\README.md");
});

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");
});
});
4 changes: 3 additions & 1 deletion packages/zee/Swabble/src/auto-reply/reply/inbound-text.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function normalizeInboundTextNewlines(input: string): string {
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll("\\n", "\n");
// Normalize actual newline characters while preserving literal "\n" sequences.
// Literal backslash-n values are common in Windows paths and user text.
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
}
Loading