MCPcopy Create free account
hub / github.com/vercel/vercel / stripWorkingDir

Function stripWorkingDir

packages/python-analysis/src/wasm/host-utils.ts:109–128  ·  view source on GitHub ↗

* Strip the workingDir prefix from an absolute path to produce a relative * path for the readFile callback. If the path is outside the workingDir, * returns `null` to signal that the file should not be accessible.

(path: string, workingDir?: string)

Source from the content-addressed store, hash-verified

107 * returns `null` to signal that the file should not be accessible.
108 */
109function stripWorkingDir(path: string, workingDir?: string): string | null {
110 // Normalize first to resolve `.` and `..` segments (e.g. /foo/../a.txt -> /a.txt)
111 const normalized = normalize(path);
112 if (!workingDir) {
113 return normalized;
114 }
115 const normalizedDir = normalize(workingDir);
116 const prefix = normalizedDir.endsWith('/')
117 ? normalizedDir
118 : normalizedDir + '/';
119 if (normalized.startsWith(prefix)) {
120 return normalized.slice(prefix.length);
121 }
122 // Handle exact match (path is the workingDir itself)
123 if (normalized === normalizedDir) {
124 return '';
125 }
126 // Path is outside workingDir -- do not expose it to the callback.
127 return null;
128}

Callers 1

readFileFunction · 0.85

Calls 1

normalizeFunction · 0.85

Tested by

no test coverage detected