mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
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:
commit
f7589160af
2 changed files with 20 additions and 1 deletions
|
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue