Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion extensions/ql-vscode/src/databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -34,14 +34,26 @@ 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);

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());
});
});
});