Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
7f2688d19This file is pinned to the selected release. Download the original to open it in your design tool.
import path from 'node:path';
export class SandboxError extends Error {
constructor(public readonly attempted: string) {
super(`path escapes repo root: ${attempted}`);
this.name = 'SandboxError';
}
}
/**
* Resolve a repo-relative path and reject anything that escapes the repo root
* (AC-4.2). All file tools must go through this.
*/
export function resolveInRepo(repoRoot: string, p: string): string {
const abs = path.resolve(repoRoot, p);
const root = path.resolve(repoRoot);
if (abs !== root && !abs.startsWith(root + path.sep)) {
throw new SandboxError(p);
}
return abs;
}
export function isKicadFile(p: string): boolean {
return /\.(kicad_sch|kicad_pcb|kicad_pro|kicad_sym|kicad_mod)$/.test(p);
}