Repository navigation
Emit strings for CycloneDX metadata property values - #5354
0Cymantek0 wants to merge 2 commits into
Conversation
The CycloneDX specification types property values as strings in all versions including the 1.3 version scancode declares, but from_headers() passed the errors and warnings lists, a null message and the extra_data mappings of the scan header to CycloneDxProperty unchanged and to_dict() serializes them as-is with attr.asdict. Tools that validate against the CycloneDX JSON schema such as cyclonedx-cli fail on the resulting BOMs on every scan. Convert property values to strings in from_headers() with a new get_property_string_value() helper. Lists of messages are joined with newlines, mappings are serialized to JSON and empty or null values are dropped. The from_headers test now expects strings and new tests check that every emitted property value is a string. Reference: aboutcode-org#5349 Signed-off-by: Shuvagata Dey <cymantekfnosz@gmail.com>
kmlyz
left a comment
There was a problem hiding this comment.
The tests/formattedcode/test_output_cyclonedx.py suite passes (17 tests) with this change. One edge case in get_property_string_value: the if not value: guard returns None for falsy scalar values such as 0 and False, instead of serializing them as '0' and 'False'. Preserving isinstance(value, (int, float)) (which covers bool) before the falsy check keeps numeric and boolean metadata properties intact. Adding 0 and False cases to test_get_property_string_value would cover this.
@kmlyz Thanks. checked and fixed. would be pushing in a moment |
Signed-off-by: Shuvagata Dey <cymantekfnosz@gmail.com>
kmlyz
left a comment
There was a problem hiding this comment.
Thanks for the quick update, @0Cymantek0. Verified on a27f793: get_property_string_value now preserves 0 as '0' and False as 'False', and all 17 tests in tests/formattedcode/test_output_cyclonedx.py pass.
|
@kmlyz Thanks for your review :) |
Fixes #5349
metadata.properties values in the CycloneDX JSON output were not strings. errors and warnings were JSON arrays, message was null and system_environment was a nested object. The CycloneDX specification types property values as strings in all versions including the declared 1.3, so schema-validating tools such as cyclonedx-cli reject the output of every scan.
Changes:
Validation:
Components still fail strict validation because fields such as author and copyright are emitted as null. Separate defect, will be filed separately.
Tasks
Run tests locally to check for errors.