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; } })(), );