fix: correctly evaluate path containment at filesystem root - #1296
awhite0030 wants to merge 3 commits into
Conversation
Fix path containment check when checking paths within a project root that is the filesystem root (like `/` or `C:\`). This caused valid files within the workspace root to be rejected because the duplicated path separator evaluated incorrectly in `startsWith`.
nc-review: needs work — 2 blocking, 2 nits@awhite0030 — there is a blocking item below. The fix to 🔴 blocking · The same if (searchPath !== root && !searchPath.startsWith(root + path.sep)) {
return `Error: Path escapes project directory: ${args.path}`;
}With 🔴 blocking ·
const root = path.resolve(containmentRoot);
const abs = path.resolve(filePath);
return abs === root || abs.startsWith(root + path.sep);With ⚪ nit · The new test covers the POSIX filesystem-root case ( ⚪ nit · The diff modifies 🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
|
Can you take a look at the bot comments and merge conflicts please @awhite0030 :) |
Description
Root cause:
isPathInsideimproperly appends a path separatorpath.septonormalizedRootbefore evaluating ifnormalizedTargetstarts with it. When the root is a filesystem root, the normalized string already ends with a path separator, creating a doubled separator (e.g.//orC:\\\), causing containment checks to fail.Fix: Conditionally append
path.seponly ifnormalizedRootdoesn't already end with one, ensuring paths are evaluated correctly under root folders.Validation:
./validate.sh .Resulted in passing all validation checks, including a new test asserting containment within the filesystem root (
/andC:\).Fixes #1240
Fixes #1240
Type of Change
Changeset
pnpm changeset) describing this change for the changelogDocs-only or internal chores need no changeset (or run
pnpm changeset --emptyto note that intentionally).Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist