Skip to content
Draft
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
30 changes: 30 additions & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,34 @@ describe("findFiles", () => {
const result = findFiles(path.join(tmpRoot, "single"), ".", "phpcs.xml");
assert.equal(result, expected);
});

// Regression test: findFiles should never return a file above the `parent`
// boundary, even when `directory` is a relative path (e.g. "..") that
// resolves outside `parent`. On unpatched code this test fails; it passes
// once PR #94 ("fix: prevent findFiles from escaping parent") is merged.
test(
"does not escape parent when directory is a relative path above workspace root",
{ todo: "Known bug β€” fixed by PR #94; marks expected failure until merged" },
() => {
// Place a config file at tmpRoot level (above the workspace root).
const aboveParent = mkFile("relative-escape-sentinel.xml");

// workspace root is one level below tmpRoot
mkDir("ws-escape");

// directory = ".." resolves to tmpRoot, which is *above* parent
const result = findFiles(
path.join(tmpRoot, "ws-escape"), // parent (workspace root)
"..", // resolves to tmpRoot β€” above parent
"relative-escape-sentinel.xml"
);

// Must NOT escape above parent β€” should return null
assert.equal(
result,
null,
`findFiles escaped parent boundary and returned ${result}`
);
}
);
});