refactor(sandbox): share bind parsing and host-path policy checks

This commit is contained in:
Peter Steinberger
2026-02-24 15:04:40 +00:00
parent 0e155690be
commit 13bfe7faa6
6 changed files with 196 additions and 107 deletions

View File

@@ -0,0 +1,34 @@
type SplitBindSpec = {
host: string;
container: string;
options: string;
};
export function splitSandboxBindSpec(spec: string): SplitBindSpec | null {
const separator = getHostContainerSeparatorIndex(spec);
if (separator === -1) {
return null;
}
const host = spec.slice(0, separator);
const rest = spec.slice(separator + 1);
const optionsStart = rest.indexOf(":");
if (optionsStart === -1) {
return { host, container: rest, options: "" };
}
return {
host,
container: rest.slice(0, optionsStart),
options: rest.slice(optionsStart + 1),
};
}
function getHostContainerSeparatorIndex(spec: string): number {
const hasDriveLetterPrefix = /^[A-Za-z]:[\\/]/.test(spec);
for (let i = hasDriveLetterPrefix ? 2 : 0; i < spec.length; i += 1) {
if (spec[i] === ":") {
return i;
}
}
return -1;
}