fix(core): ripgrep fails when pattern looks like ripgrep flag (#18858)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Smitty
2026-02-18 17:11:24 -05:00
committed by GitHub
parent 8910b2720f
commit 221ea360b9
2 changed files with 11 additions and 8 deletions

View File

@@ -1430,11 +1430,15 @@ describe('RipGrepTool', () => {
});
const result = await invocation.execute(abortSignal);
expect(mockSpawn).toHaveBeenLastCalledWith(
expect.anything(),
expect.arrayContaining(['--fixed-strings']),
expect.anything(),
);
const spawnArgs = mockSpawn.mock.calls[0][1];
expect(spawnArgs).toContain('--fixed-strings');
expect(spawnArgs).toContain('--regexp');
expect(spawnArgs).toContain('hello.world');
// Verify --fixed-strings doesn't have the pattern as its next argument
const fixedStringsIdx = spawnArgs.indexOf('--fixed-strings');
expect(spawnArgs[fixedStringsIdx + 1]).not.toBe('hello.world');
expect(result.llmContent).toContain(
'Found 1 match for pattern "hello.world"',
);

View File

@@ -387,11 +387,10 @@ class GrepToolInvocation extends BaseToolInvocation<
if (fixed_strings) {
rgArgs.push('--fixed-strings');
rgArgs.push(pattern);
} else {
rgArgs.push('--regexp', pattern);
}
rgArgs.push('--regexp', pattern);
if (context) {
rgArgs.push('--context', context.toString());
}