Skip to content

Commit 367dc9d

Browse files
authored
fix: support any key order in manual parser's top-level object json (#727)
This addresses a bug where if `appendArgsToExecutable`, the only non-string property, is the first listed in a top-level object of a JSON file matched by a manual parser, the parser would silently fail to match the listed titles.
1 parent 7999f1c commit 367dc9d

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/lib/parsers/manual.parser.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,16 @@ export class ManualParser implements GenericParser {
4040
let filePath = path.join(directory, files[i]);
4141
try {
4242
let jsonObj = fs.readJsonSync(filePath);
43-
let keys = Object.keys(jsonObj);
44-
if (typeof jsonObj[keys[0]] === "string") {
43+
let jsonObjs = Array.isArray(jsonObj) ? jsonObj : [jsonObj];
44+
for (let j = 0; j < jsonObjs.length; j++) {
4545
parsedData.success.push({
46-
extractedTitle: jsonObj.title,
47-
filePath: jsonObj.target,
48-
startInDirectory: jsonObj.startIn,
49-
launchOptions: jsonObj.launchOptions,
50-
appendArgsToExecutable: !!jsonObj.appendArgsToExecutable,
46+
extractedTitle: jsonObjs[j].title,
47+
filePath: jsonObjs[j].target,
48+
startInDirectory: jsonObjs[j].startIn,
49+
launchOptions: jsonObjs[j].launchOptions,
50+
appendArgsToExecutable:
51+
!!jsonObjs[j].appendArgsToExecutable,
5152
});
52-
} else if (typeof jsonObj[keys[0]] === "object") {
53-
for (let j = 0; j < keys.length; j++) {
54-
parsedData.success.push({
55-
extractedTitle: jsonObj[keys[j]].title,
56-
filePath: jsonObj[keys[j]].target,
57-
startInDirectory: jsonObj[keys[j]].startIn,
58-
launchOptions: jsonObj[keys[j]].launchOptions,
59-
appendArgsToExecutable:
60-
!!jsonObj[keys[j]].appendArgsToExecutable,
61-
});
62-
}
6353
}
6454
} catch (err) {
6555
parsedData.failed.push(filePath);

0 commit comments

Comments
 (0)