fix(exec): ignore malformed drive-less windows exec paths

This commit is contained in:
SnowSky1
2026-04-01 11:21:47 +08:00
committed by Peter Steinberger
parent a26f4d0f3e
commit e6ce31eb54
4 changed files with 43 additions and 0 deletions

View File

@@ -2,6 +2,10 @@ import fs from "node:fs";
import path from "node:path";
import { expandHomePrefix } from "./home-dir.js";
function isDriveLessWindowsRootedPath(value: string): boolean {
return process.platform === "win32" && /^:[\\/]/.test(value);
}
function resolveWindowsExecutableExtensions(
executable: string,
env: NodeJS.ProcessEnv | undefined,
@@ -86,6 +90,9 @@ export function resolveExecutablePath(
const expanded = rawExecutable.startsWith("~")
? expandHomePrefix(rawExecutable, { env: options?.env })
: rawExecutable;
if (isDriveLessWindowsRootedPath(expanded)) {
return undefined;
}
if (expanded.includes("/") || expanded.includes("\\")) {
if (path.isAbsolute(expanded)) {
return isExecutableFile(expanded) ? expanded : undefined;