fix: sanitize windows node argv

This commit is contained in:
Peter Steinberger
2026-01-19 14:16:45 +00:00
parent d9c20f6fa5
commit cb2add8459
2 changed files with 19 additions and 7 deletions

View File

@@ -52,13 +52,19 @@ 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, "");
const execPath = normalizeArg(process.execPath);
const normalizeCandidate = (value: string): string => normalizeArg(value).replace(/^\\\\\\?\\/, "");
const execPath = normalizeCandidate(process.execPath);
const execPathLower = execPath.toLowerCase();
const execBase = path.basename(execPath).toLowerCase();
const isExecPath = (value: string | undefined): boolean => {
if (!value) return false;
const lower = normalizeArg(value).toLowerCase();
return lower === execPathLower || path.basename(lower) === execBase;
const lower = normalizeCandidate(value).toLowerCase();
return (
lower === execPathLower ||
path.basename(lower) === execBase ||
lower.endsWith("\\node.exe") ||
lower.endsWith("/node.exe")
);
};
const filtered = argv.filter((arg, index) => index === 0 || !isExecPath(arg));
if (filtered.length < 3) return filtered;

View File

@@ -60,14 +60,20 @@ function ensureExperimentalWarningSuppressed(): boolean {
function normalizeWindowsArgv(argv: string[]): string[] {
if (process.platform !== "win32") return argv;
if (argv.length < 3) return argv;
const execPath = process.execPath;
const normalizeArg = (value: string): string => value.replace(/^"+|"+$/g, "");
const normalizeCandidate = (value: string): string => normalizeArg(value).replace(/^\\\\\\?\\/, "");
const execPath = normalizeCandidate(process.execPath);
const execPathLower = execPath.toLowerCase();
const execBase = path.basename(execPath).toLowerCase();
const normalizeArg = (value: string): string => value.replace(/^"+|"+$/g, "");
const isExecPath = (value: string | undefined): boolean => {
if (!value) return false;
const lower = normalizeArg(value).toLowerCase();
return lower === execPathLower || path.basename(lower) === execBase;
const lower = normalizeCandidate(value).toLowerCase();
return (
lower === execPathLower ||
path.basename(lower) === execBase ||
lower.endsWith("\\node.exe") ||
lower.endsWith("/node.exe")
);
};
const arg1 = path.basename(argv[1] ?? "").toLowerCase();
const arg2 = path.basename(argv[2] ?? "").toLowerCase();