@@ -189,6 +189,7 @@ def delete_tools(cyclonedx_document_json):
189189
190190 The new structure is not yet supported by the cyclonedx-python-lib, neither for
191191 serialization (output) nor deserialization (input).
192+ https://github.com/CycloneDX/cyclonedx-python-lib/issues/578
192193
193194 The tools are not used anyway in the context of loading the SBOM component data as
194195 packages.
@@ -199,6 +200,30 @@ def delete_tools(cyclonedx_document_json):
199200 return cyclonedx_document_json
200201
201202
203+ def delete_empty_dict_property (cyclonedx_document_json ):
204+ """
205+ Remove dict entry where keys are defined but no values are set, such as
206+ ``{"name": ""}``.
207+
208+ Class like cyclonedx.model.contact.OrganizationalEntity raise a
209+ NoPropertiesProvidedException while it is not enforced in the spec.
210+
211+ See https://github.com/CycloneDX/cyclonedx-python-lib/issues/600
212+ """
213+ entries_to_delete = []
214+
215+ for component in cyclonedx_document_json ["components" ]:
216+ for property_name , property_value in component .items ():
217+ if isinstance (property_value , dict ) and not any (property_value .values ()):
218+ entries_to_delete .append ((component , property_name ))
219+
220+ # Now delete the keys outside the loop
221+ for component , property_name in entries_to_delete :
222+ del component [property_name ]
223+
224+ return cyclonedx_document_json
225+
226+
202227def resolve_cyclonedx_packages (input_location ):
203228 """Resolve the packages from the `input_location` CycloneDX document file."""
204229 input_path = Path (input_location )
@@ -215,7 +240,9 @@ def resolve_cyclonedx_packages(input_location):
215240 f'CycloneDX document "{ input_path .name } " is not valid:\n { errors } '
216241 )
217242 raise ValueError (error_msg )
243+
218244 cyclonedx_document = delete_tools (cyclonedx_document )
245+ cyclonedx_document = delete_empty_dict_property (cyclonedx_document )
219246 cyclonedx_bom = Bom .from_json (data = cyclonedx_document )
220247
221248 else :
0 commit comments