fix(windows): normalize namespaced path containment checks

This commit is contained in:
Shakker
2026-02-26 18:49:26 +00:00
parent dc6e4a5b13
commit f7041fbee3
6 changed files with 45 additions and 13 deletions

View File

@@ -1,12 +1,34 @@
import { posix } from "node:path";
import { resolvePathViaExistingAncestorSync } from "../../infra/boundary-path.js";
function stripWindowsNamespacePrefix(input: string): string {
if (input.startsWith("\\\\?\\")) {
const withoutPrefix = input.slice(4);
if (withoutPrefix.toUpperCase().startsWith("UNC\\")) {
return `\\\\${withoutPrefix.slice(4)}`;
}
return withoutPrefix;
}
if (input.startsWith("//?/")) {
const withoutPrefix = input.slice(4);
if (withoutPrefix.toUpperCase().startsWith("UNC/")) {
return `//${withoutPrefix.slice(4)}`;
}
return withoutPrefix;
}
return input;
}
/**
* Normalize a POSIX host path: resolve `.`, `..`, collapse `//`, strip trailing `/`.
*/
export function normalizeSandboxHostPath(raw: string): string {
const trimmed = raw.trim();
return posix.normalize(trimmed).replace(/\/+$/, "") || "/";
const trimmed = stripWindowsNamespacePrefix(raw.trim());
if (!trimmed) {
return "/";
}
const normalized = posix.normalize(trimmed.replaceAll("\\", "/"));
return normalized.replace(/\/+$/, "") || "/";
}
/**