MCPcopy Index your code
hub / github.com/Waishnav/devspace / isPathInsideRoot

Function isPathInsideRoot

src/roots.ts:20–32  ·  view source on GitHub ↗
(path: string, root: string)

Source from the content-addressed store, hash-verified

18}
19
20export function isPathInsideRoot(path: string, root: string): boolean {
21 const resolvedPath = resolve(expandHomePath(path));
22 const resolvedRoot = resolve(expandHomePath(root));
23 const relationship = relative(resolvedRoot, resolvedPath);
24
25 return (
26 relationship === "" ||
27 (!isAbsolute(relationship) &&
28 !relationship.startsWith("..") &&
29 relationship !== ".." &&
30 !relationship.includes(`..${sep}`))
31 );
32}
33
34export function assertAllowedPath(path: string, allowedRoots: string[]): string {
35 const resolvedPath = resolve(expandHomePath(path));

Callers 5

resolveSkillReadPathFunction · 0.85
assertGitRootAllowedFunction · 0.85
resolvePathMethod · 0.85
assertAllowedPathFunction · 0.85

Calls 1

expandHomePathFunction · 0.85

Tested by

no test coverage detected