|
1 | 1 | import * as assert from 'assert'; |
2 | 2 | import * as sinon from 'sinon'; |
| 3 | +import * as vscode from 'vscode'; |
3 | 4 | import { context as cx } from '../../lib/context'; |
4 | | -import { checkAndExtractRgFlagsFromQuery, checkKillProcess } from '../../lib/ripgrep'; |
| 5 | +import { checkAndExtractRgFlagsFromQuery, checkKillProcess, rgSearch } from '../../lib/ripgrep'; |
5 | 6 |
|
6 | 7 | // Add dedicated test suite for checkAndExtractRgFlagsFromQuery |
7 | 8 | suite('checkAndExtractRgFlagsFromQuery', () => { |
@@ -161,3 +162,63 @@ suite('checkKillProcess', () => { |
161 | 162 | assert.deepStrictEqual(cx.spawnRegistry, []); |
162 | 163 | }); |
163 | 164 | }); |
| 165 | + |
| 166 | +suite('rgSearch - Path with Spaces Bug', () => { |
| 167 | + let sandbox: sinon.SinonSandbox; |
| 168 | + let spawnStub: sinon.SinonStub; |
| 169 | + |
| 170 | + setup(() => { |
| 171 | + sandbox = sinon.createSandbox(); |
| 172 | + |
| 173 | + // Minimal mock spawn that just captures the command |
| 174 | + spawnStub = sandbox.stub(require('child_process'), 'spawn').returns({ |
| 175 | + stdout: { on: sandbox.stub() }, |
| 176 | + stderr: { on: sandbox.stub() }, |
| 177 | + on: sandbox.stub(), |
| 178 | + killed: false, |
| 179 | + } as any); |
| 180 | + |
| 181 | + // Minimal required context |
| 182 | + cx.spawnRegistry = []; |
| 183 | + cx.qp = { busy: false } as any; |
| 184 | + |
| 185 | + // Minimal config mock |
| 186 | + sandbox.stub(require('../../utils/getConfig'), 'getConfig').returns({ |
| 187 | + rgPath: 'rg', |
| 188 | + rgOptions: [], |
| 189 | + rgGlobExcludes: [], |
| 190 | + addSrcPaths: [], |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
| 194 | + teardown(() => { |
| 195 | + sandbox.restore(); |
| 196 | + }); |
| 197 | + |
| 198 | + test('workspace path with spaces should be properly quoted', () => { |
| 199 | + const pathWithSpaces = '/Users/test/My Projects/workspace'; |
| 200 | + sandbox.stub(vscode.workspace, 'workspaceFolders').value([{ uri: { fsPath: pathWithSpaces } }]); |
| 201 | + |
| 202 | + rgSearch('test'); |
| 203 | + |
| 204 | + const command = spawnStub.firstCall.args[0]; |
| 205 | + assert(command.includes(`"${pathWithSpaces}"`), `Path not quoted in: ${command}`); |
| 206 | + }); |
| 207 | + |
| 208 | + test('current file path with spaces should be properly quoted', () => { |
| 209 | + const filePathWithSpaces = '/Users/test/My Documents/current file.ts'; |
| 210 | + |
| 211 | + // Mock getCurrentFilePath to return a path with spaces |
| 212 | + sandbox |
| 213 | + .stub(require('../../utils/searchCurrentFile'), 'getCurrentFilePath') |
| 214 | + .returns(filePathWithSpaces); |
| 215 | + |
| 216 | + // Set to search current file only |
| 217 | + cx.currentFileOnly = true; |
| 218 | + |
| 219 | + rgSearch('test'); |
| 220 | + |
| 221 | + const command = spawnStub.firstCall.args[0]; |
| 222 | + assert(command.includes(`"${filePathWithSpaces}"`), `File path not quoted in: ${command}`); |
| 223 | + }); |
| 224 | +}); |
0 commit comments