Skip to content
Open
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
23 changes: 23 additions & 0 deletions src/filesystem/__tests__/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,29 @@ describe('Lib Functions', () => {
expect(result).toEqual([expectedResult]);
});

it('matches glob patterns against Windows-style relative paths', async () => {
const mockEntries = [
{ name: 'index.ts', isDirectory: () => false }
];

mockFs.readdir.mockResolvedValueOnce(mockEntries as any);
mockFs.realpath.mockImplementation(async (inputPath: any) => inputPath.toString());
vi.spyOn(path, 'relative').mockReturnValueOnce('src\\index.ts');

const testDir = process.platform === 'win32' ? 'C:\\allowed\\dir' : '/allowed/dir';
const allowedDirs = process.platform === 'win32' ? ['C:\\allowed'] : ['/allowed'];

const result = await searchFilesWithValidation(
testDir,
'**/*.ts',
allowedDirs,
{}
);

const expectedResult = process.platform === 'win32' ? 'C:\\allowed\\dir\\index.ts' : '/allowed/dir/index.ts';
expect(result).toEqual([expectedResult]);
});

it('handles complex exclude patterns with wildcards', async () => {
const mockEntries = [
{ name: 'test.txt', isDirectory: () => false },
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export async function searchFilesWithValidation(
try {
await validatePath(fullPath);

const relativePath = path.relative(rootPath, fullPath);
const relativePath = path.relative(rootPath, fullPath).replace(/\\/g, '/');
const shouldExclude = excludePatterns.some(excludePattern =>
minimatch(relativePath, excludePattern, { dot: true })
);
Expand Down
Loading