Skip to content

Commit fd5da1b

Browse files
syvbscidomino
authored andcommitted
fix(core): ripgrep fails when pattern looks like ripgrep flag (google-gemini#18858)
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
1 parent e2de5c5 commit fd5da1b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/core/src/tools/ripGrep.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,11 +1430,15 @@ describe('RipGrepTool', () => {
14301430
});
14311431
const result = await invocation.execute(abortSignal);
14321432

1433-
expect(mockSpawn).toHaveBeenLastCalledWith(
1434-
expect.anything(),
1435-
expect.arrayContaining(['--fixed-strings']),
1436-
expect.anything(),
1437-
);
1433+
const spawnArgs = mockSpawn.mock.calls[0][1];
1434+
expect(spawnArgs).toContain('--fixed-strings');
1435+
expect(spawnArgs).toContain('--regexp');
1436+
expect(spawnArgs).toContain('hello.world');
1437+
1438+
// Verify --fixed-strings doesn't have the pattern as its next argument
1439+
const fixedStringsIdx = spawnArgs.indexOf('--fixed-strings');
1440+
expect(spawnArgs[fixedStringsIdx + 1]).not.toBe('hello.world');
1441+
14381442
expect(result.llmContent).toContain(
14391443
'Found 1 match for pattern "hello.world"',
14401444
);

packages/core/src/tools/ripGrep.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,10 @@ class GrepToolInvocation extends BaseToolInvocation<
387387

388388
if (fixed_strings) {
389389
rgArgs.push('--fixed-strings');
390-
rgArgs.push(pattern);
391-
} else {
392-
rgArgs.push('--regexp', pattern);
393390
}
394391

392+
rgArgs.push('--regexp', pattern);
393+
395394
if (context) {
396395
rgArgs.push('--context', context.toString());
397396
}

0 commit comments

Comments
 (0)