MCPcopy Index your code
hub / github.com/codeaashu/claude-code / resolveCwdReentry

Function resolveCwdReentry

src/tools/PowerShellTool/gitSafety.ts:23–38  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

21 * resolves against cwd to `hooks`.
22 */
23function 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.

Callers 2

isGitInternalPathPSFunction · 0.85
isDotGitPathPSFunction · 0.85

Calls 1

getCwdFunction · 0.85

Tested by

no test coverage detected