* Whether `child` is `parent` itself or sits underneath it. Case-insensitive on * Windows — NTFS is case-insensitive, and realpathSync can hand back a different * case than the lexical root, which would otherwise false-reject a valid file.
(child: string, parent: string)
| 71 | * case than the lexical root, which would otherwise false-reject a valid file. |
| 72 | */ |
| 73 | function isWithinDir(child: string, parent: string): boolean { |
| 74 | let c = child; |
| 75 | let p = parent; |
| 76 | if (process.platform === 'win32') { |
| 77 | c = c.toLowerCase(); |
| 78 | p = p.toLowerCase(); |
| 79 | } |
| 80 | return c === p || c.startsWith(p + path.sep); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Validate that a file path stays within the project root, resolving symlinks. |
no outgoing calls
no test coverage detected