From 51d911f11237eb12d63e240851f957995b8fa0e2 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Wed, 1 Jul 2020 22:49:05 -0700 Subject: [PATCH 1/2] Fix nested problem adding database starting with db-* --- extensions/ql-vscode/src/databases-ui.ts | 8 +++++++- .../no-workspace/databases-ui.test.ts | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/extensions/ql-vscode/src/databases-ui.ts b/extensions/ql-vscode/src/databases-ui.ts index 5691059f262..8c2a5572abd 100644 --- a/extensions/ql-vscode/src/databases-ui.ts +++ b/extensions/ql-vscode/src/databases-ui.ts @@ -594,7 +594,8 @@ export class DatabaseUI extends DisposableObject { if ((await fs.stat(dbPath)).isFile()) { dbPath = path.dirname(dbPath); } - if (path.basename(dbPath).startsWith('db-')) { + + if (isLikelyDbFolder(dbPath)) { dbPath = path.dirname(dbPath); } return Uri.file(dbPath); @@ -609,3 +610,8 @@ export class DatabaseUI extends DisposableObject { } } } + +const dbRegeEx = /^db-(javascript|go|cpp|java|python)$/; +function isLikelyDbFolder(dbPath: string) { + return path.basename(dbPath).match(dbRegeEx); +} diff --git a/extensions/ql-vscode/src/vscode-tests/no-workspace/databases-ui.test.ts b/extensions/ql-vscode/src/vscode-tests/no-workspace/databases-ui.test.ts index 132cd75f689..bbca853effe 100644 --- a/extensions/ql-vscode/src/vscode-tests/no-workspace/databases-ui.test.ts +++ b/extensions/ql-vscode/src/vscode-tests/no-workspace/databases-ui.test.ts @@ -25,7 +25,7 @@ describe('databases-ui', () => { it('should choose parent direcory when db-* is selected', async () => { const dir = tmp.dirSync().name; - const dbDir = path.join(dir, 'db-hucairz'); + const dbDir = path.join(dir, 'db-javascript'); await fs.mkdirs(dbDir); const uri = await fixDbUri(Uri.file(dbDir)); @@ -34,7 +34,7 @@ describe('databases-ui', () => { it('should choose parent\'s parent direcory when file selected is in db-*', async () => { const dir = tmp.dirSync().name; - const dbDir = path.join(dir, 'db-hucairz'); + const dbDir = path.join(dir, 'db-javascript'); const file = path.join(dbDir, 'nested'); await fs.mkdirs(dbDir); await fs.createFile(file); @@ -42,6 +42,18 @@ describe('databases-ui', () => { const uri = await fixDbUri(Uri.file(file)); expect(uri.toString()).to.eq(Uri.file(dir).toString()); }); - }); + it('should handle a parent whose name is db-*', async () => { + // fixes https://github.com/github/vscode-codeql/issues/482 + const dir = tmp.dirSync().name; + const parentDir = path.join(dir, 'db-hucairz'); + const dbDir = path.join(parentDir, 'db-javascript'); + const file = path.join(dbDir, 'nested'); + await fs.mkdirs(dbDir); + await fs.createFile(file); + + const uri = await fixDbUri(Uri.file(file)); + expect(uri.toString()).to.eq(Uri.file(parentDir).toString()); + }); + }); }); From b83e3e567136255662fe014e259e8ab10b0c44f2 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Wed, 1 Jul 2020 22:50:10 -0700 Subject: [PATCH 2/2] Update changelog --- extensions/ql-vscode/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 97703457030..b62c774af0d 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix unzipping of large files. - Ensure compare order is consistent when selecting two queries to compare. The first query selected is always the _from_ query and the query selected later is always the _to_ query. - Ensure added databases have zipped source locations for databases added as archives or downloaded from the internet. +- Fix bug where it is not possible to add databases starting with `db-*`. ## 1.3.0 - 22 June 2020