Skip to content

Commit a7d99cc

Browse files
committed
Fix nested problem adding database starting with db-*
1 parent 454e847 commit a7d99cc

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ export class DatabaseUI extends DisposableObject {
594594
if ((await fs.stat(dbPath)).isFile()) {
595595
dbPath = path.dirname(dbPath);
596596
}
597-
if (path.basename(dbPath).startsWith('db-')) {
597+
598+
if (isLikelyDbFolder(dbPath)) {
598599
dbPath = path.dirname(dbPath);
599600
}
600601
return Uri.file(dbPath);
@@ -609,3 +610,8 @@ export class DatabaseUI extends DisposableObject {
609610
}
610611
}
611612
}
613+
614+
const dbRegeEx = /^db-(javascript|go|cpp|java|python)$/;
615+
function isLikelyDbFolder(dbPath: string) {
616+
return path.basename(dbPath).match(dbRegeEx);
617+
}

extensions/ql-vscode/src/vscode-tests/no-workspace/databases-ui.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('databases-ui', () => {
2525

2626
it('should choose parent direcory when db-* is selected', async () => {
2727
const dir = tmp.dirSync().name;
28-
const dbDir = path.join(dir, 'db-hucairz');
28+
const dbDir = path.join(dir, 'db-javascript');
2929
await fs.mkdirs(dbDir);
3030

3131
const uri = await fixDbUri(Uri.file(dbDir));
@@ -34,14 +34,26 @@ describe('databases-ui', () => {
3434

3535
it('should choose parent\'s parent direcory when file selected is in db-*', async () => {
3636
const dir = tmp.dirSync().name;
37-
const dbDir = path.join(dir, 'db-hucairz');
37+
const dbDir = path.join(dir, 'db-javascript');
3838
const file = path.join(dbDir, 'nested');
3939
await fs.mkdirs(dbDir);
4040
await fs.createFile(file);
4141

4242
const uri = await fixDbUri(Uri.file(file));
4343
expect(uri.toString()).to.eq(Uri.file(dir).toString());
4444
});
45-
});
4645

46+
it('should handle a parent whose name is db-*', async () => {
47+
// fixes https://github.com/github/vscode-codeql/issues/482
48+
const dir = tmp.dirSync().name;
49+
const parentDir = path.join(dir, 'db-hucairz');
50+
const dbDir = path.join(parentDir, 'db-javascript');
51+
const file = path.join(dbDir, 'nested');
52+
await fs.mkdirs(dbDir);
53+
await fs.createFile(file);
54+
55+
const uri = await fixDbUri(Uri.file(file));
56+
expect(uri.toString()).to.eq(Uri.file(parentDir).toString());
57+
});
58+
});
4759
});

0 commit comments

Comments
 (0)