-
-
Notifications
You must be signed in to change notification settings - Fork 54
Description
The function call
res = __SPDX_EXPRESSION_LICENSING.validate(value)
in spdx.py's is_compound_expression function
is not checking for a compound expression.
The validate function checks whether the given string is a valid SPDX expression (simple or compound expression) and checks the license values against license_expression module's license database (including SPDX list identifiers and LicenseRef-scancode-* values).
currently
cyclonedx-python-lib/cyclonedx/spdx.py
Lines 62 to 77 in b8cbb59
| def is_compound_expression(value: str) -> bool: | |
| """Validate compound expression. | |
| .. note:: | |
| Utilizes `license-expression library`_ to | |
| validate SPDX compound expression according to `SPDX license expression spec`_. | |
| .. _SPDX license expression spec: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/ | |
| .. _license-expression library: https://github.com/nexB/license-expression | |
| """ | |
| 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) |
To check for solely a valid compound expression, it has to be:
from license_expression import get_spdx_licensing, OR, AND
...
try:
expression = __SPDX_EXPRESSION_LICENSING.parse(value, validate=True)
return type(expression) in [OR, AND]
except Exception:
...
...The class TestSpdxIsCompoundExpression test cases do not consider tests with a single valid SPDX ID from official license list or LicenseRef-scancode-* ID from license-expression's internal database.
With the definition
VALID_COMPOUND_EXPRESSIONS = {
# for valid test data see the spec: https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
'(MIT AND Apache-2.0)',
'BSD-2-Clause OR Apache-2.0',
'MIT',
'LicenseRef-scancode-3com-microcode'
}all cases succeed, even the cases with simple expression.
According to the name and description of is_compound_expression a simple expression license parameter must reult into a failure.