Skip to content

Commit 22ec4b0

Browse files
authored
Don't allow empty list names (#1886)
1 parent 2493ddd commit 22ec4b0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

extensions/ql-vscode/src/databases/db-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export class DbManager {
7676
}
7777

7878
public async addNewRemoteList(listName: string): Promise<void> {
79+
if (listName === "") {
80+
throw Error("List name cannot be empty");
81+
}
82+
7983
if (this.dbConfigStore.doesRemoteListExist(listName)) {
8084
throw Error(`A list with the name '${listName}' already exists`);
8185
}

extensions/ql-vscode/src/vscode-tests/minimal-workspace/databases/db-panel.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,35 @@ describe("db panel", () => {
549549
);
550550
});
551551

552+
describe("Name validation", () => {
553+
it("should not allow adding a new list with empty name", async () => {
554+
const dbConfig = createDbConfig();
555+
556+
await saveDbConfig(dbConfig);
557+
558+
await expect(dbManager.addNewRemoteList("")).rejects.toThrow(
559+
new Error("List name cannot be empty"),
560+
);
561+
});
562+
563+
it("should not allow adding a list with duplicate name", async () => {
564+
const dbConfig = createDbConfig({
565+
remoteLists: [
566+
{
567+
name: "my-list-1",
568+
repositories: ["owner1/repo1", "owner1/repo2"],
569+
},
570+
],
571+
});
572+
573+
await saveDbConfig(dbConfig);
574+
575+
await expect(dbManager.addNewRemoteList("my-list-1")).rejects.toThrow(
576+
new Error("A list with the name 'my-list-1' already exists"),
577+
);
578+
});
579+
});
580+
552581
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
553582
await writeJson(dbConfigFilePath, dbConfig);
554583

0 commit comments

Comments
 (0)