MCPcopy Create free account
hub / github.com/experdot/pointer / resolveRelativePathWithinRoot

Function resolveRelativePathWithinRoot

src/main/workspaceRuntime.ts:62–79  ·  view source on GitHub ↗
(rootPath: string, relativePath: string)

Source from the content-addressed store, hash-verified

60}
61
62export function resolveRelativePathWithinRoot(rootPath: string, relativePath: string): string {
63 const normalizedRelativePath = path.normalize(relativePath)
64
65 if (
66 path.isAbsolute(normalizedRelativePath) ||
67 normalizedRelativePath === '..' ||
68 normalizedRelativePath.startsWith(`..${path.sep}`)
69 ) {
70 throw new Error(`Invalid relative path: ${relativePath}`)
71 }
72
73 const resolvedPath = path.resolve(rootPath, normalizedRelativePath)
74 if (!isPathWithinRoot(resolvedPath, rootPath)) {
75 throw new Error(`Path escapes root: ${relativePath}`)
76 }
77
78 return resolvedPath
79}
80
81export function getCurrentAttachmentsDirectory(): string {
82 if (!currentWorkspaceRoot) {

Callers 1

resolveAttachmentPathFunction · 0.90

Calls 1

isPathWithinRootFunction · 0.85

Tested by

no test coverage detected