Skip to content

Commit

Permalink
fix: SPDX-expression-validation internal crashes are cought and handl…
Browse files Browse the repository at this point in the history
…ed (#471)

Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck authored Oct 16, 2023
1 parent 0ebaa21 commit 5fa66a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 5fa66a0

Please sign in to comment.