Skip to content

Commit 3087886

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 3087886

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

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: 43 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,48 @@ 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+
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
370+
{
371+
name: "codespaces-codeql",
372+
uri: { path: "codespaces-codeql\\codeql-custom-queries-cpp" },
373+
},
374+
] as WorkspaceFolder[]);
375+
376+
Object.defineProperty(process, "platform", {
377+
value: "win32",
378+
});
379+
380+
wizard = new SkeletonQueryWizard(
381+
mockCli,
382+
jest.fn(),
383+
credentials,
384+
extLogger,
385+
mockDatabaseManager,
386+
token,
387+
);
388+
389+
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
390+
});
391+
});
350392
});
351393

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

0 commit comments

Comments
 (0)