(path: string, root: string)
| 24 | } |
| 25 | |
| 26 | export function pathWithinRoot(path: string, root: string): boolean { |
| 27 | const normalizedPath = comparablePath(path); |
| 28 | const normalizedRoot = comparablePath(root); |
| 29 | if ( |
| 30 | !normalizedPath || |
| 31 | !normalizedRoot || |
| 32 | !isNormalizedAbsolutePath(normalizedPath) || |
| 33 | !isNormalizedAbsolutePath(normalizedRoot) || |
| 34 | isWindowsDrivePath(path) !== isWindowsDrivePath(root) |
| 35 | ) { |
| 36 | return false; |
| 37 | } |
| 38 | if (normalizedRoot === '/') return normalizedPath.startsWith('/'); |
| 39 | const separator = isWindowsDrivePath(root) ? '\\' : '/'; |
| 40 | const subtreePrefix = normalizedRoot.endsWith(separator) |
| 41 | ? normalizedRoot |
| 42 | : `${normalizedRoot}${separator}`; |
| 43 | return normalizedPath === normalizedRoot || normalizedPath.startsWith(subtreePrefix); |
| 44 | } |
| 45 | |
| 46 | export function samePath(a: string, b: string): boolean { |
| 47 | if (isWindowsDrivePath(a) !== isWindowsDrivePath(b)) return false; |
no test coverage detected