MCPcopy Create free account
hub / github.com/anus-dev/ANUS / isWithinRoot

Function isWithinRoot

packages/core/src/utils/fileUtils.ts:36–55  ·  view source on GitHub ↗
(
  pathToCheck: string,
  rootDirectory: string,
)

Source from the content-addressed store, hash-verified

34 * @returns True if the path is within the root directory, false otherwise.
35 */
36export function isWithinRoot(
37 pathToCheck: string,
38 rootDirectory: string,
39): boolean {
40 const normalizedPathToCheck = path.resolve(pathToCheck);
41 const normalizedRootDirectory = path.resolve(rootDirectory);
42
43 // Ensure the rootDirectory path ends with a separator for correct startsWith comparison,
44 // unless it's the root path itself (e.g., '/' or 'C:\').
45 const rootWithSeparator =
46 normalizedRootDirectory === path.sep ||
47 normalizedRootDirectory.endsWith(path.sep)
48 ? normalizedRootDirectory
49 : normalizedRootDirectory + path.sep;
50
51 return (
52 normalizedPathToCheck === normalizedRootDirectory ||
53 normalizedPathToCheck.startsWith(rootWithSeparator)
54 );
55}
56
57/**
58 * Determines if a file is likely binary based on content sampling.

Callers 3

fileUtils.test.tsFile · 0.85
#resolvePromptMethod · 0.85
isWorkspaceTrustedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected