Skip to content

Commit

Permalink
fix: Components with no version (optional since 1.4) produce invalid …
Browse files Browse the repository at this point in the history
…BOM output in XML #150

Signed-off-by: Paul Horton <[email protected]>
  • Loading branch information
madpah committed Jan 27, 2022
1 parent 15b081b commit 70d25c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
8 changes: 0 additions & 8 deletions cyclonedx/exception/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@
from . import CycloneDxException


class ComponentVersionRequiredException(CycloneDxException):
"""
Exception raised when attempting to output to an SBOM version that mandates a Component has a version,
but one is not available/present.
"""
pass


class FormatNotSupportedException(CycloneDxException):
"""
Exception raised when attempting to output a BOM to a format not supported in the requested version.
Expand Down
9 changes: 3 additions & 6 deletions cyclonedx/output/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from . import BaseOutput, SchemaVersion
from .schema import BaseSchemaVersion, SchemaVersion1Dot0, SchemaVersion1Dot1, SchemaVersion1Dot2, SchemaVersion1Dot3, \
SchemaVersion1Dot4
from ..exception.output import ComponentVersionRequiredException
from ..model import ExternalReference, HashType, OrganizationalEntity, OrganizationalContact, Tool
from ..model.bom import Bom
from ..model.component import Component
Expand Down Expand Up @@ -147,11 +146,9 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
ElementTree.SubElement(component_element, 'version').text = component.version
else:
if not component.version:
raise ComponentVersionRequiredException(
f'Component "{str(component)}" has no version but the target schema version mandates '
f'Components have a version specified'
)
ElementTree.SubElement(component_element, 'version').text = component.version
ElementTree.SubElement(component_element, 'version')
else:
ElementTree.SubElement(component_element, 'version').text = component.version

# hashes
if component.hashes:
Expand Down

0 comments on commit 70d25c8

Please sign in to comment.