mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 10:42:43 +00:00
fix(windows): normalize namespaced path containment checks
This commit is contained in:
@@ -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(/\/+$/, "") || "/";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user