Skip to content

Commit 815bfa0

Browse files
Copilotpelikhan
andauthored
Fix Windows path handling in VSCode extension context menu (issue #1504) (#1903)
* Initial plan * Fix Windows path handling in VSCode extension context menu Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Add tests for Windows path handling fix Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
1 parent 8f135fb commit 815bfa0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/core/test/resources.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,31 @@ describe("resources", async () => {
100100
assert(result.files[0].filename.includes("readme.md"));
101101
});
102102
*/
103+
104+
await test("should reject Windows-style paths that look like URIs (issue #1504)", async () => {
105+
// This tests the issue fixed in VSCode extension
106+
// Windows paths like "c:\Users\..." should not be treated as valid resources
107+
const windowsPath = "c:\\Users\\test\\file.txt";
108+
109+
const result = await tryResolveResource(windowsPath);
110+
111+
// This should return undefined because it's not a valid resource
112+
// The fix in VSCode extension ensures we pass file:// URIs instead
113+
assert.equal(result, undefined);
114+
});
115+
116+
await test("should handle proper file URIs correctly (issue #1504 fix)", async () => {
117+
// This tests what the VSCode extension fix ensures is sent
118+
const testFilePath = join(tempDir, "test-file.txt");
119+
writeFileSync(testFilePath, "test content");
120+
121+
// Convert to proper file URI (what VSCode should send after our fix)
122+
const fileUri = pathToFileURL(testFilePath).href;
123+
124+
const result = await tryResolveResource(fileUri);
125+
126+
assert(result);
127+
assert.equal(result.files.length, 1);
128+
assert.equal(result.files[0].filename, testFilePath);
129+
});
103130
});

packages/vscode/src/fragmentcommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function activateFragmentCommands(state: ExtensionState): void {
8282
parameters = await showPromptParametersQuickPicks(script, defaultValues);
8383
if (parameters === undefined) return;
8484
scriptId = script.id;
85-
files = fileOrFolders?.map((f) => f.fsPath) || [fileOrFolder?.fsPath];
85+
files = fileOrFolders?.map((f) => f.toString()) || [fileOrFolder?.toString()];
8686
}
8787
await state.requestAI({
8888
fragment: { files: files.filter((f) => !!f) },

0 commit comments

Comments
 (0)