diff --git a/.gitignore b/.gitignore index 8fa326f97..f45220d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,6 @@ roots/ .python-version build/ .mise.toml + +# Ignore IntelliJ IDEA module file +cdxgen.iml \ No newline at end of file diff --git a/utils.js b/utils.js index 191fe894f..0373544d0 100644 --- a/utils.js +++ b/utils.js @@ -512,7 +512,7 @@ export function getLicenses(pkg) { license = [license]; } return adjustLicenseInformation( - license.map((l) => { + license.filter((l) => l !== undefined).map((l) => { let licenseContent = {}; if (typeof l === "string" || l instanceof String) { if ( diff --git a/utils.test.js b/utils.test.js index 574000dc7..83d55795e 100644 --- a/utils.test.js +++ b/utils.test.js @@ -2398,6 +2398,26 @@ test("get licenses", () => { expression: "GPL-3.0-only WITH Classpath-exception-2.0", }, ]); + + licenses = getLicenses({ + license: [ + "GPL-3.0-only WITH Classpath-exception-2.0", + "NOT-GPL-2.1+" + ] + }); + expect(licenses).toEqual([ + { + expression: "GPL-3.0-only WITH Classpath-exception-2.0", + }, + { + expression: "NOT-GPL-2.1+", + } + ]); + + licenses = getLicenses({ + license: undefined, + }); + expect(licenses).toEqual(undefined); }); test("parsePkgJson", async () => {