MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / isWithinDir

Function isWithinDir

src/utils.ts:73–81  ·  view source on GitHub ↗

* Whether `child` is `parent` itself or sits underneath it. Case-insensitive on * Windows — NTFS is case-insensitive, and realpathSync can hand back a different * case than the lexical root, which would otherwise false-reject a valid file.

(child: string, parent: string)

Source from the content-addressed store, hash-verified

71 * case than the lexical root, which would otherwise false-reject a valid file.
72 */
73function isWithinDir(child: string, parent: string): boolean {
74 let c = child;
75 let p = parent;
76 if (process.platform === 'win32') {
77 c = c.toLowerCase();
78 p = p.toLowerCase();
79 }
80 return c === p || c.startsWith(p + path.sep);
81}
82
83/**
84 * Validate that a file path stays within the project root, resolving symlinks.

Callers 1

validatePathWithinRootFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected