diff --git a/src/filesystem/__tests__/lib.test.ts b/src/filesystem/__tests__/lib.test.ts index e0ae61224f..27a47670d4 100644 --- a/src/filesystem/__tests__/lib.test.ts +++ b/src/filesystem/__tests__/lib.test.ts @@ -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 }, diff --git a/src/filesystem/lib.ts b/src/filesystem/lib.ts index ce4af9f38a..f3b8eba35b 100644 --- a/src/filesystem/lib.ts +++ b/src/filesystem/lib.ts @@ -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 }) );