mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Don't remove empty lines in shell startup scripts. Fixes #58
This commit is contained in:
parent
846c62e4e0
commit
57ce17e7f5
2 changed files with 27 additions and 3 deletions
|
|
@ -28,7 +28,7 @@ export function removeLinesMatchingPattern(filePath, pattern) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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(os.EOL), "utf-8");
|
fs.writeFileSync(filePath, updatedLines.join(os.EOL), "utf-8");
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,12 @@ function shouldRemoveLine(line, pattern) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes("\n") || line.includes("\r") || line.includes("\u2028") || line.includes("\u2029")) {
|
if (
|
||||||
|
line.includes("\n") ||
|
||||||
|
line.includes("\r") ||
|
||||||
|
line.includes("\u2028") ||
|
||||||
|
line.includes("\u2029")
|
||||||
|
) {
|
||||||
// If the line contains newlines, something has gone wrong in splitting
|
// If the line contains newlines, something has gone wrong in splitting
|
||||||
// \u2028 and \u2029 are Unicode line separator characters (line and paragraph separators)
|
// \u2028 and \u2029 are Unicode line separator characters (line and paragraph separators)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -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