Skip to content

Commit

Permalink
fix: check parsing for incorrect manifest.json of 3rd party addons
Browse files Browse the repository at this point in the history
  • Loading branch information
Revyn112 committed Nov 14, 2024
1 parent 680d4de commit 42dcb35
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/renderer/utils/IncompatibleAddOnsCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,34 @@ export class IncompatibleAddOnsCheck {
const dirEntries = fs.readdirSync(filePath);

if (dirEntries.includes(manifestFileName)) {
const manifest = JSON.parse(fs.readFileSync(path.join(filePath, manifestFileName), 'utf8'));
try {
const manifest = JSON.parse(fs.readFileSync(path.join(filePath, manifestFileName), 'utf8'));

for (const item of addon.incompatibleAddons) {
// This checks the configuration item properties (if set) against the manifest.json file
// entry property values. If all properties match, the add-on is considered incompatible.
// packageVersion syntax follows: https://www.npmjs.com/package/semver
// Future improvement would be to allow for regular expressions in the configuration item.
const titleMatches = !item.title || manifest.title === item.title;
const creatorMatches = !item.creator || manifest.creator === item.creator;
const packageVersionTargeted =
!item.packageVersion || semverSatisfies(manifest.package_version, item.packageVersion);
for (const item of addon.incompatibleAddons) {
// This checks the configuration item properties (if set) against the manifest.json file
// entry property values. If all properties match, the add-on is considered incompatible.
// packageVersion syntax follows: https://www.npmjs.com/package/semver
// Future improvement would be to allow for regular expressions in the configuration item.
const titleMatches = !item.title || manifest.title === item.title;
const creatorMatches = !item.creator || manifest.creator === item.creator;
const packageVersionTargeted =
!item.packageVersion || semverSatisfies(manifest.package_version, item.packageVersion);

Check failure on line 43 in src/renderer/utils/IncompatibleAddOnsCheck.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`

if (titleMatches && creatorMatches && packageVersionTargeted) {
// Also write this to the log as this info might be useful for support.
console.log(`Incompatible Add-On found: ${manifest.title}: ${item.description}`);
if (titleMatches && creatorMatches && packageVersionTargeted) {
// Also write this to the log as this info might be useful for support.
console.log(`Incompatible Add-On found: ${manifest.title}: ${item.description}`);

incompatibleAddons.push({
title: item.title,
creator: item.creator,
packageVersion: item.packageVersion,
folder: entry,
description: item.description,
});
}
incompatibleAddons.push({
title: item.title,
creator: item.creator,
packageVersion: item.packageVersion,
folder: entry,
description: item.description,
});
}
}

Check failure on line 57 in src/renderer/utils/IncompatibleAddOnsCheck.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `··············`
} catch (e) {
console.warn(`Failed to read or parse manifest.json in ${filePath}:`, e.message);
}
}
}
Expand Down

0 comments on commit 42dcb35

Please sign in to comment.