Skip to content

Commit 5fa66a0

Browse files
authored
fix: SPDX-expression-validation internal crashes are cought and handled (#471)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 0ebaa21 commit 5fa66a0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cyclonedx/spdx.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def is_compound_expression(value: str) -> bool:
6666
.. _SPDX license expression spec: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
6767
.. _license-expression library: https://github.com/nexB/license-expression
6868
"""
69-
return 0 == len(
70-
__SPDX_EXPRESSION_LICENSING.validate(value).errors
71-
)
69+
try:
70+
res = __SPDX_EXPRESSION_LICENSING.validate(value)
71+
except Exception:
72+
# the throw happens when internals crash due to unexpected input characters.
73+
return False
74+
return 0 == len(res.errors)

tests/test_spdx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def test_positive(self, valid_expression: str) -> None:
9292
'MIT AND Apache-2.0 OR something-unknown'
9393
'something invalid',
9494
'(c) John Doe',
95+
'Apache License, Version 2.0'
9596
)
9697
def test_negative(self, invalid_expression: str) -> None:
9798
actual = spdx.is_compound_expression(invalid_expression)

0 commit comments

Comments
 (0)