(root: string, input: string)
| 186 | } |
| 187 | |
| 188 | async 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 | |
| 219 | function splitFile(content: string): { lines: string[]; eol: string; finalNewline: boolean } { |
| 220 | const eol = content.includes("\r\n") ? "\r\n" : "\n"; |
no test coverage detected