Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/pi-fff/src/aux-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export function resolveAuxRoot(
return null;
}

export function isOutsideWorkspaceRelativePath(relativePath: string): boolean {
return (
path.isAbsolute(relativePath) ||
relativePath === ".." ||
relativePath.startsWith(`..${path.sep}`)
);
}

// Decide whether a `path` parameter should route to the workspace finder or
// to an aux finder. Accepts absolute paths, `~`-prefixed paths, and relative
// paths escaping the workspace (`../other-project`); everything is resolved
Expand All @@ -147,7 +155,7 @@ export function routePathConstraint(
candidate = path.resolve(cwd, candidate);
}
const rel = path.relative(cwd, candidate);
if (rel !== ".." && !rel.startsWith(`..${path.sep}`)) return null;
if (!isOutsideWorkspaceRelativePath(rel)) return null;
return resolveAuxRoot(candidate);
}

Expand Down
9 changes: 9 additions & 0 deletions packages/pi-fff/test/aux-finders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import {
isOutsideWorkspaceRelativePath,
resolveAuxRoot,
rootCovers,
routePathConstraint,
Expand All @@ -28,6 +29,14 @@ describe("routePathConstraint", () => {
expect(route).toEqual({ root: "/tmp", suffix: "" });
});

if (process.platform === "win32") {
test("treats a cross-volume relative result as outside the workspace", () => {
const rel = path.win32.relative("D:\\workspace", "C:\\target");
expect(rel).toBe("C:\\target");
expect(isOutsideWorkspaceRelativePath(rel)).toBe(true);
});
}

test("splits glob suffix from existing dir prefix", () => {
const route = routePathConstraint("/tmp/**/*.ts", cwd);
expect(route).toEqual({ root: "/tmp", suffix: "**/*.ts" });
Expand Down
Loading