(rootPath: string, relativePath: string)
| 60 | } |
| 61 | |
| 62 | export 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 | |
| 81 | export function getCurrentAttachmentsDirectory(): string { |
| 82 | if (!currentWorkspaceRoot) { |
no test coverage detected