refactor(sandbox): share container-path utils and tighten fs bridge tests

This commit is contained in:
Peter Steinberger
2026-02-25 01:59:43 +00:00
parent c736778b3f
commit eb4a93a8db
5 changed files with 41 additions and 30 deletions

View File

@@ -0,0 +1,15 @@
import path from "node:path";
export function normalizeContainerPath(value: string): string {
const normalized = path.posix.normalize(value);
return normalized === "." ? "/" : normalized;
}
export function isPathInsideContainerRoot(root: string, target: string): boolean {
const normalizedRoot = normalizeContainerPath(root);
const normalizedTarget = normalizeContainerPath(target);
if (normalizedRoot === "/") {
return true;
}
return normalizedTarget === normalizedRoot || normalizedTarget.startsWith(`${normalizedRoot}/`);
}