MCPcopy Index your code
hub / github.com/Waishnav/devspace / resolveConfinedPath

Function resolveConfinedPath

src/apply-patch.ts:188–217  ·  view source on GitHub ↗
(root: string, input: string)

Source from the content-addressed store, hash-verified

186}
187
188async function resolveConfinedPath(root: string, input: string): Promise<string> {
189 if (!input || input.includes("\0") || isAbsolute(input)) {
190 throw patchError(`path must be relative to the workspace: ${input}`);
191 }
192
193 const rootPath = await realpath(root);
194 const target = resolve(rootPath, input);
195 if (!isInside(rootPath, target)) {
196 throw patchError(`path escapes the workspace: ${input}`);
197 }
198
199 let existing = target;
200 while (true) {
201 try {
202 const resolved = await realpath(existing);
203 if (!isInside(rootPath, resolved)) {
204 throw patchError(`path resolves outside the workspace: ${input}`);
205 }
206 break;
207 } catch (error) {
208 const code = (error as NodeJS.ErrnoException).code;
209 if (code !== "ENOENT") throw error;
210 const parent = dirname(existing);
211 if (parent === existing) throw error;
212 existing = parent;
213 }
214 }
215
216 return target;
217}
218
219function splitFile(content: string): { lines: string[]; eol: string; finalNewline: boolean } {
220 const eol = content.includes("\r\n") ? "\r\n" : "\n";

Callers 1

applyPatchFunction · 0.85

Calls 2

patchErrorFunction · 0.85
isInsideFunction · 0.85

Tested by

no test coverage detected