feat(core): Handle special characters in file search paths (#6680)
This commit is contained in:
parent
b4ecdd67ec
commit
6aff66f501
|
@ -566,6 +566,35 @@ describe('FileSearch', () => {
|
||||||
expect(limitedResults).toEqual(['file1.js', 'file2.js']);
|
expect(limitedResults).toEqual(['file1.js', 'file2.js']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle file paths with special characters that need escaping', async () => {
|
||||||
|
tmpDir = await createTmpDir({
|
||||||
|
src: {
|
||||||
|
'file with (special) chars.txt': '',
|
||||||
|
'another-file.txt': '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileSearch = FileSearchFactory.create({
|
||||||
|
projectRoot: tmpDir,
|
||||||
|
useGitignore: false,
|
||||||
|
useGeminiignore: false,
|
||||||
|
ignoreDirs: [],
|
||||||
|
cache: false,
|
||||||
|
cacheTtl: 0,
|
||||||
|
enableRecursiveFileSearch: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await fileSearch.initialize();
|
||||||
|
|
||||||
|
// Search for the file using a pattern that contains special characters.
|
||||||
|
// The `unescapePath` function should handle the escaped path correctly.
|
||||||
|
const results = await fileSearch.search(
|
||||||
|
'src/file with \\(special\\) chars.txt',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(results).toEqual(['src/file with (special) chars.txt']);
|
||||||
|
});
|
||||||
|
|
||||||
describe('DirectoryFileSearch', () => {
|
describe('DirectoryFileSearch', () => {
|
||||||
it('should search for files in the current directory', async () => {
|
it('should search for files in the current directory', async () => {
|
||||||
tmpDir = await createTmpDir({
|
tmpDir = await createTmpDir({
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { Ignore, loadIgnoreRules } from './ignore.js';
|
||||||
import { ResultCache } from './result-cache.js';
|
import { ResultCache } from './result-cache.js';
|
||||||
import { crawl } from './crawler.js';
|
import { crawl } from './crawler.js';
|
||||||
import { AsyncFzf, FzfResultItem } from 'fzf';
|
import { AsyncFzf, FzfResultItem } from 'fzf';
|
||||||
|
import { unescapePath } from '../paths.js';
|
||||||
|
|
||||||
export interface FileSearchOptions {
|
export interface FileSearchOptions {
|
||||||
projectRoot: string;
|
projectRoot: string;
|
||||||
|
@ -116,7 +117,7 @@ class RecursiveFileSearch implements FileSearch {
|
||||||
throw new Error('Engine not initialized. Call initialize() first.');
|
throw new Error('Engine not initialized. Call initialize() first.');
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = pattern || '*';
|
pattern = unescapePath(pattern) || '*';
|
||||||
|
|
||||||
let filteredCandidates;
|
let filteredCandidates;
|
||||||
const { files: candidates, isExactMatch } =
|
const { files: candidates, isExactMatch } =
|
||||||
|
|
Loading…
Reference in New Issue