fix: strip noisy windows argv entries

This commit is contained in:
Peter Steinberger
2026-01-19 15:04:26 +00:00
parent cf2fe4b4c5
commit 0af4eda8c5
2 changed files with 14 additions and 4 deletions

View File

@@ -51,7 +51,11 @@ export async function runCli(argv: string[] = process.argv) {
function stripWindowsNodeExec(argv: string[]): string[] {
if (process.platform !== "win32") return argv;
const normalizeArg = (value: string): string => value.replace(/^['"]+|['"]+$/g, "").trim();
const normalizeArg = (value: string): string =>
value
.replace(/[\u0000-\u001f\u007f]/g, "")
.replace(/^['"]+|['"]+$/g, "")
.trim();
const normalizeCandidate = (value: string): string =>
normalizeArg(value).replace(/^\\\\\\?\\/, "");
const execPath = normalizeCandidate(process.execPath);
@@ -64,7 +68,8 @@ function stripWindowsNodeExec(argv: string[]): string[] {
lower === execPathLower ||
path.basename(lower) === execBase ||
lower.endsWith("\\node.exe") ||
lower.endsWith("/node.exe")
lower.endsWith("/node.exe") ||
lower.includes("node.exe")
);
};
const filtered = argv.filter((arg, index) => index === 0 || !isExecPath(arg));

View File

@@ -60,7 +60,11 @@ function ensureExperimentalWarningSuppressed(): boolean {
function normalizeWindowsArgv(argv: string[]): string[] {
if (process.platform !== "win32") return argv;
if (argv.length < 3) return argv;
const normalizeArg = (value: string): string => value.replace(/^['"]+|['"]+$/g, "").trim();
const normalizeArg = (value: string): string =>
value
.replace(/[\u0000-\u001f\u007f]/g, "")
.replace(/^['"]+|['"]+$/g, "")
.trim();
const normalizeCandidate = (value: string): string =>
normalizeArg(value).replace(/^\\\\\\?\\/, "");
const execPath = normalizeCandidate(process.execPath);
@@ -73,7 +77,8 @@ function normalizeWindowsArgv(argv: string[]): string[] {
lower === execPathLower ||
path.basename(lower) === execBase ||
lower.endsWith("\\node.exe") ||
lower.endsWith("/node.exe")
lower.endsWith("/node.exe") ||
lower.includes("node.exe")
);
};
const arg1 = path.basename(argv[1] ?? "").toLowerCase();