Skip to content

Commit 14fb1b5

Browse files
committed
Fix problem with detecting storage folder on windows
The `getFirstStoragePath()` method would break on windows: ``` Path contains invalid characters: /c:/git-repo/codespaces-codeql (codeQL.createSkeletonQuery) ``` This makes sense, since we're looking to get the parent folder by splitting for `/`. In windows, paths use `\` instead of `/`. So let's detect the platform and add a test for this case.
1 parent a6ffb6b commit 14fb1b5

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ export class SkeletonQueryWizard {
104104
// so we need to get the parent folder
105105
if (firstFolder.uri.path.includes("codeql-custom-queries")) {
106106
// slice off the last part of the path and return the parent folder
107-
return firstFolder.uri.path.split("/").slice(0, -1).join("/");
107+
if (process.platform === "win32") {
108+
return firstFolder.uri.path.split("\\").slice(0, -1).join("\\");
109+
} else {
110+
return firstFolder.uri.path.split("/").slice(0, -1).join("/");
111+
}
108112
} else {
109113
// if the first folder is not a ql pack, then we are in a normal workspace
110114
return firstFolder.uri.path;

extensions/ql-vscode/test/vscode-tests/cli-integration/skeleton-query-wizard.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe("SkeletonQueryWizard", () => {
305305
it("should return the first workspace folder", async () => {
306306
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
307307
{
308-
name: "codeql-custom-queries-cpp",
308+
name: "codespaces-codeql",
309309
uri: { path: "codespaces-codeql" },
310310
},
311311
] as WorkspaceFolder[]);
@@ -347,6 +347,49 @@ describe("SkeletonQueryWizard", () => {
347347
expect(wizard.getFirstStoragePath()).toEqual("vscode-codeql-starter");
348348
});
349349
});
350+
351+
describe("if user is on windows", () => {
352+
let originalPlatform: string;
353+
354+
beforeEach(() => {
355+
originalPlatform = process.platform;
356+
Object.defineProperty(process, "platform", {
357+
value: "win32",
358+
});
359+
});
360+
361+
afterEach(() => {
362+
originalPlatform = process.platform;
363+
Object.defineProperty(process, "platform", {
364+
value: originalPlatform,
365+
});
366+
});
367+
368+
it("should return the first workspace folder", async () => {
369+
console.log("process.platform", process.platform);
370+
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
371+
{
372+
name: "codespaces-codeql",
373+
uri: { path: "codespaces-codeql\\codeql-custom-queries-cpp" },
374+
},
375+
] as WorkspaceFolder[]);
376+
377+
Object.defineProperty(process, "platform", {
378+
value: "win32",
379+
});
380+
381+
wizard = new SkeletonQueryWizard(
382+
mockCli,
383+
jest.fn(),
384+
credentials,
385+
extLogger,
386+
mockDatabaseManager,
387+
token,
388+
);
389+
390+
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
391+
});
392+
});
350393
});
351394

352395
describe("findDatabaseItemByNwo", () => {

0 commit comments

Comments
 (0)