From fbde4968e7dd484914862a1964f0054023967038 Mon Sep 17 00:00:00 2001 From: CKY- Date: Wed, 13 Nov 2024 13:34:55 -0700 Subject: [PATCH] fix: carrage return not being ignored in replace line of write file. --- src/backend/common/handlers/fileWriterProcessor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/common/handlers/fileWriterProcessor.js b/src/backend/common/handlers/fileWriterProcessor.js index a5ba1c9c3..02624e5cb 100644 --- a/src/backend/common/handlers/fileWriterProcessor.js +++ b/src/backend/common/handlers/fileWriterProcessor.js @@ -15,7 +15,6 @@ const doesFileExist = (filepath) => { function removeLines(filepath, lines = []) { const contents = fs.readFileSync(filepath, { encoding: "utf8" }); - return `${contents .split('\n') .filter(l => l != null && l.trim() !== "") @@ -27,7 +26,7 @@ function removeLinesWithText(filepath, text) { const contents = fs.readFileSync(filepath, { encoding: "utf8" }); return `${contents .split('\n') - .map(l => { + .map((l) => { return l.replace('\r', ""); }) .filter(l => l != null && l.trim() !== "") @@ -51,14 +50,17 @@ function replaceLinesWithText(filepath, text, replacement) { const contents = fs.readFileSync(filepath, { encoding: "utf8" }); return `${contents .split('\n') + .map((l) => { + return l.replace('\r', ""); + }) .filter(l => l != null && l.trim() !== "") - .map(l => { + .map((l) => { return l === text ? replacement : l; }) .join('\n')}\n`; } -exports.run = async effect => { +exports.run = async (effect) => { if (effect == null || effect.filepath == null) { return; }