Merge pull request #61 from AikidoSec/respect-empty-lines-in-shell-startup-files

Don't remove empty lines in shell startup scripts. Fixes #58
This commit is contained in:
Sander Declerck 2025-09-18 10:24:38 +02:00 committed by GitHub
commit f7589160af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -30,7 +30,7 @@ export function removeLinesMatchingPattern(filePath, pattern, eol) {
eol = eol || os.EOL; eol = eol || os.EOL;
const fileContent = fs.readFileSync(filePath, "utf-8"); 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)); const updatedLines = lines.filter((line) => !shouldRemoveLine(line, pattern));
fs.writeFileSync(filePath, updatedLines.join(eol), "utf-8"); fs.writeFileSync(filePath, updatedLines.join(eol), "utf-8");
} }

View file

@ -222,5 +222,24 @@ describe("Zsh shell integration", () => {
); );
assert.ok(content.includes("alias ls=")); 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);
});
}); });
}); });