diff --git a/packages/safe-chain/src/shell-integration/helpers.js b/packages/safe-chain/src/shell-integration/helpers.js index e3320a1..d6c19d7 100644 --- a/packages/safe-chain/src/shell-integration/helpers.js +++ b/packages/safe-chain/src/shell-integration/helpers.js @@ -30,7 +30,7 @@ export function removeLinesMatchingPattern(filePath, pattern, eol) { eol = eol || os.EOL; const fileContent = fs.readFileSync(filePath, "utf-8"); - const lines = fileContent.split(/[\r\n\u2028\u2029]+/); + const lines = fileContent.split(/[\r\n\u2028\u2029]/); const updatedLines = lines.filter((line) => !shouldRemoveLine(line, pattern)); fs.writeFileSync(filePath, updatedLines.join(eol), "utf-8"); } diff --git a/packages/safe-chain/src/shell-integration/supported-shells/zsh.spec.js b/packages/safe-chain/src/shell-integration/supported-shells/zsh.spec.js index 95c12ac..99106ec 100644 --- a/packages/safe-chain/src/shell-integration/supported-shells/zsh.spec.js +++ b/packages/safe-chain/src/shell-integration/supported-shells/zsh.spec.js @@ -222,5 +222,24 @@ describe("Zsh shell integration", () => { ); assert.ok(content.includes("alias ls=")); }); + + it("should respect empty lines and comments", () => { + const initialContent = [ + "#!/bin/zsh", + "", + "# Some comment", + "", + "", + "", + "# Another comment", + ].join("\n"); + + fs.writeFileSync(mockStartupFile, initialContent, "utf-8"); + + zsh.teardown(knownAikidoTools); + + const content = fs.readFileSync(mockStartupFile, "utf-8"); + assert.strictEqual(content, initialContent); + }); }); });