( workspaceRoot: string, requestedPath: string, )
| 1 | import path from 'node:path'; |
| 2 | |
| 3 | export function resolveWorkspacePath( |
| 4 | workspaceRoot: string, |
| 5 | requestedPath: string, |
| 6 | ): string { |
| 7 | if (!path.isAbsolute(requestedPath)) { |
| 8 | throw new Error(`ACP path must be absolute: ${requestedPath}`); |
| 9 | } |
| 10 | |
| 11 | const resolved = path.resolve(requestedPath); |
| 12 | const root = path.resolve(workspaceRoot); |
| 13 | |
| 14 | if (resolved === root) return resolved; |
| 15 | if (resolved.startsWith(root + path.sep)) return resolved; |
| 16 | |
| 17 | throw new Error(`Path escapes WORKSPACE_ROOT: ${requestedPath}`); |
| 18 | } |
no outgoing calls
no test coverage detected