evOo-local/scripts/test-path-fix.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

80 lines
1.7 KiB
TypeScript

function normalizeWorkspacePathOld(value: string): string {
const normalized = value.replace(/\\/g, "/").replace(/^\/+/, "");
const segments = normalized.split("/").filter(Boolean);
if (segments.some((segment) => segment === "." || segment === "..")) {
throw new Error("Path escapes the computer workspace");
}
return segments.join("/");
}
function normalizeWorkspacePathNew(value: string): string {
const normalized = value.replace(/\\/g, "/").replace(/^\/+/, "");
const rawSegments = normalized.split("/").filter(Boolean);
if (rawSegments.some((segment) => segment === "..")) {
throw new Error("Path escapes the computer workspace");
}
const segments = rawSegments.filter((segment) => segment !== ".");
return segments.join("/");
}
console.log(
"Old '.' ->",
(() => {
try {
return normalizeWorkspacePathOld(".");
} catch (e) {
return e.message;
}
})(),
);
console.log(
"New '.' ->",
(() => {
try {
return normalizeWorkspacePathNew(".");
} catch (e) {
return e.message;
}
})(),
);
console.log(
"New './apex-trading' ->",
(() => {
try {
return normalizeWorkspacePathNew("./apex-trading");
} catch (e) {
return e.message;
}
})(),
);
console.log(
"New '..' ->",
(() => {
try {
return normalizeWorkspacePathNew("..");
} catch (e) {
return e.message;
}
})(),
);
console.log(
"New '../foo' ->",
(() => {
try {
return normalizeWorkspacePathNew("../foo");
} catch (e) {
return e.message;
}
})(),
);
console.log(
"New 'foo/bar' ->",
(() => {
try {
return normalizeWorkspacePathNew("foo/bar");
} catch (e) {
return e.message;
}
})(),
);