Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cyclonedx/spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def is_compound_expression(value: str) -> bool:
.. _SPDX license expression spec: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
.. _license-expression library: https://github.com/nexB/license-expression
"""
return 0 == len(
__SPDX_EXPRESSION_LICENSING.validate(value).errors
)
try:
res = __SPDX_EXPRESSION_LICENSING.validate(value)
except Exception:
# the throw happens when internals crash due to unexpected input characters.
return False
return 0 == len(res.errors)
1 change: 1 addition & 0 deletions tests/test_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_positive(self, valid_expression: str) -> None:
'MIT AND Apache-2.0 OR something-unknown'
'something invalid',
'(c) John Doe',
'Apache License, Version 2.0'
)
def test_negative(self, invalid_expression: str) -> None:
actual = spdx.is_compound_expression(invalid_expression)
Expand Down