Merge branch 'main' into escape-special-chars-in-shell

This commit is contained in:
Sander Declerck 2025-10-23 09:52:38 +02:00
commit 8447d3cac5
No known key found for this signature in database
62 changed files with 2212 additions and 4032 deletions

View file

@ -9,7 +9,7 @@ function escapeArg(arg) {
// and escape characters that are special even inside double quotes
if (shellMetaChars.test(arg)) {
// Inside double quotes, we need to escape: " $ ` \
return '"' + arg.replace(/(["`$\\])/g, '\\$1') + '"';
return '"' + arg.replace(/(["`$\\])/g, "\\$1") + '"';
}
return arg;
}
@ -50,11 +50,23 @@ export async function safeSpawn(command, args, options = {}) {
child = spawn(fullPath, args, options);
}
// When stdio is piped, we need to collect the output
let stdout = "";
let stderr = "";
child.stdout?.on("data", (data) => {
stdout += data.toString();
});
child.stderr?.on("data", (data) => {
stderr += data.toString();
});
child.on("close", (code) => {
resolve({
status: code,
stdout: Buffer.from(""),
stderr: Buffer.from(""),
stdout: stdout,
stderr: stderr,
});
});