From cdfae0b9d3516a9d7b365e44902a8230b6f470cd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 8 Jan 2026 22:28:48 +0000 Subject: [PATCH] fix(daemon): normalize audit paths --- src/daemon/runtime-paths.ts | 14 ++++++++++---- src/daemon/service-audit.ts | 11 ++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/daemon/runtime-paths.ts b/src/daemon/runtime-paths.ts index e6fc7d616..b0444af4f 100644 --- a/src/daemon/runtime-paths.ts +++ b/src/daemon/runtime-paths.ts @@ -12,10 +12,15 @@ const VERSION_MANAGER_MARKERS = [ "/nvs/", ]; +function getPathModule(platform: NodeJS.Platform) { + return platform === "win32" ? path.win32 : path.posix; +} + function normalizeForCompare(input: string, platform: NodeJS.Platform): string { - const normalized = path.normalize(input); + const pathModule = getPathModule(platform); + const normalized = pathModule.normalize(input).replaceAll("\\", "/"); if (platform === "win32") { - return normalized.replaceAll("\\", "/").toLowerCase(); + return normalized.toLowerCase(); } return normalized; } @@ -31,12 +36,13 @@ function buildSystemNodeCandidates( return ["/usr/local/bin/node", "/usr/bin/node"]; } if (platform === "win32") { + const pathModule = getPathModule(platform); const programFiles = env.ProgramFiles ?? "C:\\Program Files"; const programFilesX86 = env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)"; return [ - path.join(programFiles, "nodejs", "node.exe"), - path.join(programFilesX86, "nodejs", "node.exe"), + pathModule.join(programFiles, "nodejs", "node.exe"), + pathModule.join(programFilesX86, "nodejs", "node.exe"), ]; } return []; diff --git a/src/daemon/service-audit.ts b/src/daemon/service-audit.ts index dc88504cf..cf40e758e 100644 --- a/src/daemon/service-audit.ts +++ b/src/daemon/service-audit.ts @@ -194,10 +194,15 @@ function isBunRuntime(execPath: string): boolean { return base === "bun" || base === "bun.exe"; } +function getPathModule(platform: NodeJS.Platform) { + return platform === "win32" ? path.win32 : path.posix; +} + function normalizePathEntry(entry: string, platform: NodeJS.Platform): string { - const normalized = path.normalize(entry); + const pathModule = getPathModule(platform); + const normalized = pathModule.normalize(entry).replaceAll("\\", "/"); if (platform === "win32") { - return normalized.replaceAll("\\", "/").toLowerCase(); + return normalized.toLowerCase(); } return normalized; } @@ -221,7 +226,7 @@ function auditGatewayServicePath( const expected = getMinimalServicePathParts({ platform }); const parts = servicePath - .split(path.delimiter) + .split(getPathModule(platform).delimiter) .map((entry) => entry.trim()) .filter(Boolean); const normalizedParts = parts.map((entry) =>