From 8e637db794adba6cea3d7a704c9139f8d6b47df6 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Sun, 7 Jun 2026 12:54:17 +0800 Subject: [PATCH] fix: handle literal \r\n escape sequences in hwpod-node insert-after/replace anchor matching --- tools/src/hwpod-node-lib.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/src/hwpod-node-lib.ts b/tools/src/hwpod-node-lib.ts index 541d9bf5..53160174 100644 --- a/tools/src/hwpod-node-lib.ts +++ b/tools/src/hwpod-node-lib.ts @@ -701,7 +701,8 @@ function lineEndingFromArgs(args: any, fallback: string) { } function normalizeContentLineEndings(content: string, lineEnding: string, finalNewline: boolean) { - const normalized = String(content).replace(/\r\n?/gu, "\n"); + const unescaped = String(content).replace(/\\r\\n/gu, "\r\n").replace(/\\n/gu, "\n").replace(/\\r(?!\n)/gu, "\r"); + const normalized = unescaped.replace(/\r\n?/gu, "\n"); const withFinal = finalNewline && !normalized.endsWith("\n") ? `${normalized}\n` : normalized; return lineEnding === "\r\n" ? withFinal.replace(/\n/gu, "\r\n") : withFinal; }