Skip to content

Commit 290917e

Browse files
authored
fix(effects): File Writer Newline Escapes (#3025) (#3029)
* fix(effects): File Writer Escaped Newlines (#3025) - Replace \n with a newline, but replace \\n with a backslash n. - Temporarily uses the `sub`, ASCII 0x1A, html  character for temporary staging to skip over the newline regex. - #3025 * More Flexible Replacement Token - I do have to question why anyone might be writing low ASCII control characters to a file, but they can do so freely now.
1 parent f27b3e7 commit 290917e

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/backend/common/handlers/fileWriterProcessor.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require("fs");
44
const path = require("path");
55
const logger = require("../../logwrapper");
6+
const uuid = require("uuid").v4;
67

78
function doesTextExistInFile(filepath, text) {
89
const contents = fs.readFileSync(filepath, { encoding: "utf8" });
@@ -66,7 +67,13 @@ exports.run = async (effect) => {
6667
}
6768

6869
let text = effect.text || "";
70+
let escapedNewline = "␚";
71+
while (text.includes(escapedNewline)) {
72+
escapedNewline = `␚${uuid()}␚`;
73+
}
74+
text = text.replace(/\\\\n/g, escapedNewline);
6975
text = effect.writeMode === "suffix" ? text.replace(/\\n/g, "\n") : text.replace(/\\n/g, "\n").trim();
76+
text = text.replaceAll(escapedNewline, "\\n");
7077

7178
try {
7279
if (effect.writeMode === "suffix") {

0 commit comments

Comments
 (0)