MCPcopy Create free account
hub / github.com/apache/maka / isNormalizedAbsolutePath

Function isNormalizedAbsolutePath

packages/core/src/absolute-path.ts:2–24  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

1/** Pure absolute-path helpers shared by permission and sandbox-boundary contracts. */
2export function isNormalizedAbsolutePath(path: string): boolean {
3 if (!path || path.includes('\0')) return false;
4 if (isWindowsDrivePath(path)) {
5 if (
6 path.includes(':', 2) ||
7 path.startsWith('\\\\') ||
8 path.startsWith('\\\\?\\') ||
9 path.startsWith('\\\\.\\')
10 )
11 return false;
12 if (path.includes('/') || (path.length > 3 && path.endsWith('\\'))) return false;
13 if (path.length === 3) return true;
14 return !path
15 .slice(3)
16 .split('\\')
17 .some((segment) => segment === '' || segment === '.' || segment === '..');
18 }
19 if (!path.startsWith('/') || path.includes('\\')) return false;
20 if (path.length > 1 && path.endsWith('/')) return false;
21 return !path
22 .split('/')
23 .some((segment, index) => index > 0 && (segment === '' || segment === '.' || segment === '..'));
24}
25
26export function pathWithinRoot(path: string, root: string): boolean {
27 const normalizedPath = comparablePath(path);

Callers 5

pathWithinRootFunction · 0.85
isCanonicalWindowsPathFunction · 0.85
validateFilesystemFunction · 0.85
validateFilesystemFunction · 0.85
decodeSandboxProfileFunction · 0.85

Calls 1

isWindowsDrivePathFunction · 0.85

Tested by

no test coverage detected