Skip to content

Commit 70d25c8

Browse files
committed
fix: Components with no version (optional since 1.4) produce invalid BOM output in XML #150
Signed-off-by: Paul Horton <[email protected]>
1 parent 15b081b commit 70d25c8

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

cyclonedx/exception/output.py

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
from . import CycloneDxException
2323

2424

25-
class ComponentVersionRequiredException(CycloneDxException):
26-
"""
27-
Exception raised when attempting to output to an SBOM version that mandates a Component has a version,
28-
but one is not available/present.
29-
"""
30-
pass
31-
32-
3325
class FormatNotSupportedException(CycloneDxException):
3426
"""
3527
Exception raised when attempting to output a BOM to a format not supported in the requested version.

cyclonedx/output/xml.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from . import BaseOutput, SchemaVersion
2525
from .schema import BaseSchemaVersion, SchemaVersion1Dot0, SchemaVersion1Dot1, SchemaVersion1Dot2, SchemaVersion1Dot3, \
2626
SchemaVersion1Dot4
27-
from ..exception.output import ComponentVersionRequiredException
2827
from ..model import ExternalReference, HashType, OrganizationalEntity, OrganizationalContact, Tool
2928
from ..model.bom import Bom
3029
from ..model.component import Component
@@ -147,11 +146,9 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
147146
ElementTree.SubElement(component_element, 'version').text = component.version
148147
else:
149148
if not component.version:
150-
raise ComponentVersionRequiredException(
151-
f'Component "{str(component)}" has no version but the target schema version mandates '
152-
f'Components have a version specified'
153-
)
154-
ElementTree.SubElement(component_element, 'version').text = component.version
149+
ElementTree.SubElement(component_element, 'version')
150+
else:
151+
ElementTree.SubElement(component_element, 'version').text = component.version
155152

156153
# hashes
157154
if component.hashes:

0 commit comments

Comments
 (0)