(parentPath: string, childPath: string)
| 209 | * @returns True if childPath is a subpath of parentPath, false otherwise. |
| 210 | */ |
| 211 | export function isSubpath(parentPath: string, childPath: string): boolean { |
| 212 | const isWindows = os.platform() === 'win32'; |
| 213 | const pathModule = isWindows ? path.win32 : path; |
| 214 | |
| 215 | // On Windows, path.relative is case-insensitive. On POSIX, it's case-sensitive. |
| 216 | const relative = pathModule.relative(parentPath, childPath); |
| 217 | |
| 218 | return ( |
| 219 | !relative.startsWith(`..${pathModule.sep}`) && |
| 220 | relative !== '..' && |
| 221 | !pathModule.isAbsolute(relative) |
| 222 | ); |
| 223 | } |
no outgoing calls
no test coverage detected