refactor: add inbound context helpers
This commit is contained in:
19
src/auto-reply/reply/inbound-text.test.ts
Normal file
19
src/auto-reply/reply/inbound-text.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { normalizeInboundTextNewlines } from "./inbound-text.js";
|
||||
|
||||
describe("normalizeInboundTextNewlines", () => {
|
||||
it("keeps real newlines", () => {
|
||||
expect(normalizeInboundTextNewlines("a\nb")).toBe("a\nb");
|
||||
});
|
||||
|
||||
it("normalizes CRLF/CR to LF", () => {
|
||||
expect(normalizeInboundTextNewlines("a\r\nb")).toBe("a\nb");
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
7
src/auto-reply/reply/inbound-text.ts
Normal file
7
src/auto-reply/reply/inbound-text.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function normalizeInboundTextNewlines(input: string): string {
|
||||
const text = input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
||||
if (text.includes("\n")) return text;
|
||||
if (!text.includes("\\n")) return text;
|
||||
return text.replaceAll("\\n", "\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user