mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 06:54:15 -07:00
fix windows escaping (and broken tests) (#19011)
This commit is contained in:
committed by
GitHub
parent
c7237f0c79
commit
e7e4c68c5c
@@ -1023,7 +1023,7 @@ describe('useTextBuffer', () => {
|
|||||||
useTextBuffer({ viewport, escapePastedPaths: true }),
|
useTextBuffer({ viewport, escapePastedPaths: true }),
|
||||||
);
|
);
|
||||||
act(() => result.current.insert(filePath, { paste: true }));
|
act(() => result.current.insert(filePath, { paste: true }));
|
||||||
expect(getBufferState(result).text).toBe(`@${filePath} `);
|
expect(getBufferState(result).text).toBe(`@${escapePath(filePath)} `);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not prepend @ to an invalid file path on insert', () => {
|
it('should not prepend @ to an invalid file path on insert', () => {
|
||||||
@@ -1042,7 +1042,7 @@ describe('useTextBuffer', () => {
|
|||||||
);
|
);
|
||||||
const quotedPath = `'${filePath}'`;
|
const quotedPath = `'${filePath}'`;
|
||||||
act(() => result.current.insert(quotedPath, { paste: true }));
|
act(() => result.current.insert(quotedPath, { paste: true }));
|
||||||
expect(getBufferState(result).text).toBe(`@${filePath} `);
|
expect(getBufferState(result).text).toBe(`@${escapePath(filePath)} `);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not prepend @ to short text that is not a path', () => {
|
it('should not prepend @ to short text that is not a path', () => {
|
||||||
@@ -1063,9 +1063,11 @@ describe('useTextBuffer', () => {
|
|||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useTextBuffer({ viewport, escapePastedPaths: true }),
|
useTextBuffer({ viewport, escapePastedPaths: true }),
|
||||||
);
|
);
|
||||||
const filePaths = `${file1} ${file2}`;
|
const filePaths = `${escapePath(file1)} ${escapePath(file2)}`;
|
||||||
act(() => result.current.insert(filePaths, { paste: true }));
|
act(() => result.current.insert(filePaths, { paste: true }));
|
||||||
expect(getBufferState(result).text).toBe(`@${file1} @${file2} `);
|
expect(getBufferState(result).text).toBe(
|
||||||
|
`@${escapePath(file1)} @${escapePath(file2)} `,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle multiple paths with escaped spaces', () => {
|
it('should handle multiple paths with escaped spaces', () => {
|
||||||
@@ -1077,13 +1079,12 @@ describe('useTextBuffer', () => {
|
|||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useTextBuffer({ viewport, escapePastedPaths: true }),
|
useTextBuffer({ viewport, escapePastedPaths: true }),
|
||||||
);
|
);
|
||||||
// Construct escaped path string: "/path/to/my\ file.txt /path/to/other.txt"
|
|
||||||
|
|
||||||
const filePaths = `${escapePath(file1)} ${file2}`;
|
const filePaths = `${escapePath(file1)} ${escapePath(file2)}`;
|
||||||
|
|
||||||
act(() => result.current.insert(filePaths, { paste: true }));
|
act(() => result.current.insert(filePaths, { paste: true }));
|
||||||
expect(getBufferState(result).text).toBe(
|
expect(getBufferState(result).text).toBe(
|
||||||
`@${escapePath(file1)} @${file2} `,
|
`@${escapePath(file1)} @${escapePath(file2)} `,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ describe('handleAtCommand', () => {
|
|||||||
path.join(testRootDir, 'path', 'to', 'my file.txt'),
|
path.join(testRootDir, 'path', 'to', 'my file.txt'),
|
||||||
fileContent,
|
fileContent,
|
||||||
);
|
);
|
||||||
const escapedpath = path.join(testRootDir, 'path', 'to', 'my\\ file.txt');
|
|
||||||
const query = `@${escapedpath}`;
|
const query = `@${core.escapePath(filePath)}`;
|
||||||
|
|
||||||
const result = await handleAtCommand({
|
const result = await handleAtCommand({
|
||||||
query,
|
query,
|
||||||
@@ -960,8 +960,8 @@ describe('handleAtCommand', () => {
|
|||||||
path.join(testRootDir, 'spaced file.txt'),
|
path.join(testRootDir, 'spaced file.txt'),
|
||||||
fileContent,
|
fileContent,
|
||||||
);
|
);
|
||||||
const escapedPath = path.join(testRootDir, 'spaced\\ file.txt');
|
|
||||||
const query = `Check @${escapedPath}, it has spaces.`;
|
const query = `Check @${core.escapePath(filePath)}, it has spaces.`;
|
||||||
|
|
||||||
const result = await handleAtCommand({
|
const result = await handleAtCommand({
|
||||||
query,
|
query,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import type { Config, FileSearch } from '@google/gemini-cli-core';
|
|||||||
import {
|
import {
|
||||||
FileSearchFactory,
|
FileSearchFactory,
|
||||||
FileDiscoveryService,
|
FileDiscoveryService,
|
||||||
|
escapePath,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import type { FileSystemStructure } from '@google/gemini-cli-test-utils';
|
import type { FileSystemStructure } from '@google/gemini-cli-test-utils';
|
||||||
import { createTmpDir, cleanupTmpDir } from '@google/gemini-cli-test-utils';
|
import { createTmpDir, cleanupTmpDir } from '@google/gemini-cli-test-utils';
|
||||||
@@ -90,7 +91,7 @@ describe('useAtCompletion', () => {
|
|||||||
'src/',
|
'src/',
|
||||||
'src/components/',
|
'src/components/',
|
||||||
'file.txt',
|
'file.txt',
|
||||||
'src/components/Button\\ with\\ spaces.tsx',
|
`${escapePath('src/components/Button with spaces.tsx')}`,
|
||||||
'src/components/Button.tsx',
|
'src/components/Button.tsx',
|
||||||
'src/index.js',
|
'src/index.js',
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -277,8 +277,8 @@ export function makeRelative(
|
|||||||
*/
|
*/
|
||||||
export function escapePath(filePath: string): string {
|
export function escapePath(filePath: string): string {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
// Windows: Double quote if it contains space or special chars
|
// Windows: Double quote if it contains special chars
|
||||||
if (/[\s()[\]{};|&^$!@%`'~]/.test(filePath)) {
|
if (/[\s&()[\]{}^=;!'+,`~%$@#]/.test(filePath)) {
|
||||||
return `"${filePath}"`;
|
return `"${filePath}"`;
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user