Skip to content

Commit

Permalink
fix: enforce package root elements are <types> and <version>
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Nov 12, 2024
1 parent 44eefe6 commit d0414fe
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/helpers/parsePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ export async function parsePackageXml(xmlContent: string): Promise<SalesforcePac
// Parse the XML string to an object
const parsed: SalesforcePackageXml = (await parser.parseStringPromise(xmlContent)) as SalesforcePackageXml;

// Ensure the root <Package> exists
if (!parsed.Package) {
return null;
}

// Validate that the root <Package> contains only allowed keys (<types>, <version>)
const allowedKeys = new Set(['types', 'version']);
const packageKeys = Object.keys(parsed.Package).filter((key) => key !== '$'); // Ignore the '$' key

const hasUnexpectedKeys = packageKeys.some((key) => !allowedKeys.has(key));
if (hasUnexpectedKeys) {
return null;
}

// Normalize the structure if 'name' or 'version' are wrapped in arrays
if (parsed.Package?.types) {
parsed.Package.types.forEach((type) => {
Expand Down

0 comments on commit d0414fe

Please sign in to comment.