(path: string)
| 1 | /** Pure absolute-path helpers shared by permission and sandbox-boundary contracts. */ |
| 2 | export function isNormalizedAbsolutePath(path: string): boolean { |
| 3 | if (!path || path.includes('\0')) return false; |
| 4 | if (isWindowsDrivePath(path)) { |
| 5 | if ( |
| 6 | path.includes(':', 2) || |
| 7 | path.startsWith('\\\\') || |
| 8 | path.startsWith('\\\\?\\') || |
| 9 | path.startsWith('\\\\.\\') |
| 10 | ) |
| 11 | return false; |
| 12 | if (path.includes('/') || (path.length > 3 && path.endsWith('\\'))) return false; |
| 13 | if (path.length === 3) return true; |
| 14 | return !path |
| 15 | .slice(3) |
| 16 | .split('\\') |
| 17 | .some((segment) => segment === '' || segment === '.' || segment === '..'); |
| 18 | } |
| 19 | if (!path.startsWith('/') || path.includes('\\')) return false; |
| 20 | if (path.length > 1 && path.endsWith('/')) return false; |
| 21 | return !path |
| 22 | .split('/') |
| 23 | .some((segment, index) => index > 0 && (segment === '' || segment === '.' || segment === '..')); |
| 24 | } |
| 25 | |
| 26 | export function pathWithinRoot(path: string, root: string): boolean { |
| 27 | const normalizedPath = comparablePath(path); |
no test coverage detected