fix: land #569 (thanks @bjesuiter)

This commit is contained in:
Peter Steinberger
2026-01-09 15:05:47 +01:00
parent 7dcf19d902
commit 92b792b3f0
3 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
import { spawn } from "node:child_process";
function sanitizeBuffer(input) {
const out = Buffer.allocUnsafe(input.length);
for (let i = 0; i < input.length; i++) {
const b = input[i];
// Keep: tab/newline/carriage return + printable ASCII; replace everything else.
out[i] = b === 9 || b === 10 || b === 13 || (b >= 32 && b <= 126) ? b : 63;
}
return out;
}
const [command, ...args] = process.argv.slice(2);
if (!command) {
process.stderr.write(
"Usage: node scripts/ci-sanitize-output.mjs <cmd> [args...]\n",
);
process.exit(2);
}
const child = spawn(command, args, {
stdio: ["ignore", "pipe", "pipe"],
shell: process.platform === "win32",
});
child.stdout.on("data", (chunk) => {
process.stdout.write(sanitizeBuffer(Buffer.from(chunk)));
});
child.stderr.on("data", (chunk) => {
process.stderr.write(sanitizeBuffer(Buffer.from(chunk)));
});
child.on("exit", (code, signal) => {
if (signal) process.exit(1);
process.exit(code ?? 1);
});