* If a normalized path starts with `../ /`, it re-enters cwd * via the parent — resolve it to the cwd-relative form. posix.normalize * preserves leading `..` (no cwd context), so `../project/hooks` with * cwd=/x/project stays `../project/hooks` and misses the `hooks/` prefix * match
(normalized: string)
| 21 | * resolves against cwd to `hooks`. |
| 22 | */ |
| 23 | function resolveCwdReentry(normalized: string): string { |
| 24 | if (!normalized.startsWith('../')) return normalized |
| 25 | const cwdBase = basename(getCwd()).toLowerCase() |
| 26 | if (!cwdBase) return normalized |
| 27 | // Iteratively strip `../<cwd-basename>/` pairs (handles `../../p/p/hooks` |
| 28 | // when cwd has repeated basename segments is unlikely, but one-level is |
| 29 | // the common attack). |
| 30 | const prefix = '../' + cwdBase + '/' |
| 31 | let s = normalized |
| 32 | while (s.startsWith(prefix)) { |
| 33 | s = s.slice(prefix.length) |
| 34 | } |
| 35 | // Also handle exact `../<cwd-basename>` (no trailing slash) |
| 36 | if (s === '../' + cwdBase) return '.' |
| 37 | return s |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Normalize PS arg text → canonical path for git-internal matching. |
no test coverage detected