Skip to content

Commit 15b081b

Browse files
committed
fix: expression not supported in Component Licsnes for version 1.0
Signed-off-by: Paul Horton <[email protected]>
1 parent df43a9b commit 15b081b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cyclonedx/output/schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def component_supports_bom_ref_attribute(self) -> bool:
6565
def component_supports_mime_type_attribute(self) -> bool:
6666
return True
6767

68+
def component_supports_licenses_expression(self) -> bool:
69+
return True
70+
6871
def component_version_optional(self) -> bool:
6972
return False
7073

@@ -230,6 +233,9 @@ def component_supports_author(self) -> bool:
230233
def component_supports_bom_ref_attribute(self) -> bool:
231234
return False
232235

236+
def component_supports_licenses_expression(self) -> bool:
237+
return False
238+
233239
def component_supports_mime_type_attribute(self) -> bool:
234240
return False
235241

cyclonedx/output/xml.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
159159

160160
# licenses
161161
if component.licenses:
162+
license_output: bool = False
162163
licenses_e = ElementTree.SubElement(component_element, 'licenses')
163164
for license in component.licenses:
164165
if license.license:
@@ -177,8 +178,14 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
177178
license_text_e_attrs).text = license.license.text.content
178179

179180
ElementTree.SubElement(license_e, 'text').text = license.license.id
181+
license_output = True
180182
else:
181-
ElementTree.SubElement(licenses_e, 'expression').text = license.expression
183+
if self.component_supports_licenses_expression():
184+
ElementTree.SubElement(licenses_e, 'expression').text = license.expression
185+
license_output = True
186+
187+
if not license_output:
188+
component_element.remove(licenses_e)
182189

183190
# cpe
184191
if component.cpe:

0 commit comments

Comments
 (0)