Fix drag and drop escaping (#18965)

This commit is contained in:
Tommaso Sciortino
2026-02-12 18:27:56 -08:00
committed by GitHub
parent 00f73b73bc
commit d82f66973f
8 changed files with 492 additions and 399 deletions

View File

@@ -145,6 +145,7 @@ describe('handleAtCommand', () => {
afterEach(async () => {
abortController.abort();
await fsPromises.rm(testRootDir, { recursive: true, force: true });
vi.unstubAllGlobals();
});
it('should pass through query if no @ command is present', async () => {
@@ -319,6 +320,46 @@ describe('handleAtCommand', () => {
);
}, 10000);
it('should correctly handle double-quoted paths with spaces', async () => {
// Mock platform to win32 so unescapePath strips quotes
vi.stubGlobal(
'process',
Object.create(process, {
platform: {
get: () => 'win32',
},
}),
);
const fileContent = 'Content of file with spaces';
const filePath = await createTestFile(
path.join(testRootDir, 'my folder', 'my file.txt'),
fileContent,
);
// On Windows, the user might provide: @"path/to/my file.txt"
const query = `@"${filePath}"`;
const result = await handleAtCommand({
query,
config: mockConfig,
addItem: mockAddItem,
onDebugMessage: mockOnDebugMessage,
messageId: 126,
signal: abortController.signal,
});
const relativePath = getRelativePath(filePath);
expect(result).toEqual({
processedQuery: [
{ text: `@${relativePath}` },
{ text: '\n--- Content from referenced files ---' },
{ text: `\nContent from @${relativePath}:\n` },
{ text: fileContent },
{ text: '\n--- End of content ---' },
],
});
});
it('should correctly handle file paths with narrow non-breaking space (NNBSP)', async () => {
const nnbsp = '\u202F';
const fileContent = 'NNBSP file content.';