Skip to content

Commit b8144cc

Browse files
fix(tools): escape backslashes in grepSearch shell args
1 parent d805db9 commit b8144cc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/utils/tools/filesystem.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ export async function grepSearch(
145145

146146
// Try ripgrep first for better performance
147147
try {
148+
const escapedPattern = pattern.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
149+
const escapedDirPath = dirPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
150+
148151
const { stdout } = await execShell(
149-
`rg --line-number --no-heading --smart-case "${pattern.replace(/"/g, '\\"')}" "${dirPath}"`,
152+
`rg --line-number --no-heading --smart-case "${escapedPattern}" "${escapedDirPath}"`,
150153
);
151154
// v8 ignore next
152155
return { content: stdout || 'No matches found' };

0 commit comments

Comments
 (0)