Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f37fe13

Browse files
authored
Fix registry lookup response (#224)
fixes #58, check if valid value is returned
1 parent a6b49d2 commit f37fe13

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/client/common/registry.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export interface IRegistry {
1919
}
2020

2121
export class RegistryImplementation implements IRegistry {
22-
public getKeys(key: string, hive: Hive, arch?: Architecture) {
23-
return getRegistryKeys({ hive: translateHive(hive), arch: translateArchitecture(arch), key });
22+
public async getKeys(key: string, hive: Hive, arch?: Architecture) {
23+
return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key });
2424
}
25-
public getValue(key: string, hive: Hive, arch?: Architecture, name: string = '') {
26-
return getRegistryValue({ hive: translateHive(hive), arch: translateArchitecture(arch), key }, name);
25+
public async getValue(key: string, hive: Hive, arch?: Architecture, name: string = '') {
26+
return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name);
2727
}
2828
}
2929

@@ -38,28 +38,28 @@ export function getArchitectureDislayName(arch?: Architecture) {
3838
}
3939
}
4040

41-
function getRegistryValue(options: Registry.Options, name: string = '') {
41+
async function getRegistryValue(options: Registry.Options, name: string = '') {
4242
return new Promise<string | undefined | null>((resolve, reject) => {
4343
new Registry(options).get(name, (error, result) => {
44-
if (error) {
44+
if (error || !result || typeof result.value !== 'string') {
4545
return resolve(undefined);
4646
}
4747
resolve(result.value);
4848
});
4949
});
5050
}
51-
function getRegistryKeys(options: Registry.Options): Promise<string[]> {
51+
async function getRegistryKeys(options: Registry.Options): Promise<string[]> {
5252
// https://github.com/python/peps/blob/master/pep-0514.txt#L85
5353
return new Promise<string[]>((resolve, reject) => {
5454
new Registry(options).keys((error, result) => {
55-
if (error) {
55+
if (error || !Array.isArray(result)) {
5656
return resolve([]);
5757
}
58-
resolve(result.map(item => item.key));
58+
resolve(result.filter(item => typeof item.key === 'string').map(item => item.key));
5959
});
6060
});
6161
}
62-
function translateArchitecture(arch?: Architecture): RegistryArchitectures | null | undefined {
62+
function translateArchitecture(arch?: Architecture): RegistryArchitectures | undefined {
6363
switch (arch) {
6464
case Architecture.x86:
6565
return RegistryArchitectures.x86;
@@ -69,7 +69,7 @@ function translateArchitecture(arch?: Architecture): RegistryArchitectures | nul
6969
return;
7070
}
7171
}
72-
function translateHive(hive: Hive): string | null | undefined {
72+
function translateHive(hive: Hive): string | undefined {
7373
switch (hive) {
7474
case Hive.HKCU:
7575
return Registry.HKCU;

tslint.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
"PromiseLike"
4444
],
4545
"completed-docs": false,
46+
"no-void-expression": false,
47+
"no-non-null-assertion": false,
4648
"no-unsafe-any": false,
4749
"prefer-type-cast": false,
4850
"function-name": false,
4951
"variable-name": false,
50-
"no-void-expression": false,
5152
"no-backbone-get-set-outside-model": false,
52-
"underscore-consistent-invocation": false,
53-
"no-non-null-assertion": false
53+
"underscore-consistent-invocation": false
5454
}
5555
}

0 commit comments

Comments
 (0)