Skip to content

Commit

Permalink
fix: expression not supported in Component Licsnes for version 1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Horton <[email protected]>
  • Loading branch information
madpah committed Jan 27, 2022
1 parent df43a9b commit 15b081b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cyclonedx/output/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def component_supports_bom_ref_attribute(self) -> bool:
def component_supports_mime_type_attribute(self) -> bool:
return True

def component_supports_licenses_expression(self) -> bool:
return True

def component_version_optional(self) -> bool:
return False

Expand Down Expand Up @@ -230,6 +233,9 @@ def component_supports_author(self) -> bool:
def component_supports_bom_ref_attribute(self) -> bool:
return False

def component_supports_licenses_expression(self) -> bool:
return False

def component_supports_mime_type_attribute(self) -> bool:
return False

Expand Down
9 changes: 8 additions & 1 deletion cyclonedx/output/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:

# licenses
if component.licenses:
license_output: bool = False
licenses_e = ElementTree.SubElement(component_element, 'licenses')
for license in component.licenses:
if license.license:
Expand All @@ -177,8 +178,14 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
license_text_e_attrs).text = license.license.text.content

ElementTree.SubElement(license_e, 'text').text = license.license.id
license_output = True
else:
ElementTree.SubElement(licenses_e, 'expression').text = license.expression
if self.component_supports_licenses_expression():
ElementTree.SubElement(licenses_e, 'expression').text = license.expression
license_output = True

if not license_output:
component_element.remove(licenses_e)

# cpe
if component.cpe:
Expand Down

0 comments on commit 15b081b

Please sign in to comment.