Skip to content

Commit 85c52bb

Browse files
authored
fix(sbom): handle SPDX expression licenses in extract_licenses (#1898)
CycloneDX allows licenses as either {"license": {"id": "..."}} or {"expression": "MIT OR Apache-2.0"}. The expression form was silently dropped, producing an empty license field in the CSV output.
1 parent 82d03f1 commit 85c52bb

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

deploy/sbom/sbom_to_csv.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ def extract_licenses(component: dict) -> str:
2323
licenses = component.get("licenses", [])
2424
ids = []
2525
for entry in licenses:
26-
lic = entry.get("license", {})
27-
ids.append(lic.get("id") or lic.get("name", ""))
26+
if "expression" in entry:
27+
ids.append(entry["expression"])
28+
else:
29+
lic = entry.get("license", {})
30+
ids.append(lic.get("id") or lic.get("name", ""))
2831
return " | ".join(filter(None, ids))
2932

3033

0 commit comments

Comments
 (0)