Skip to content

Commit 700df46

Browse files
committed
Catch all invalid license key characters
A fix was previously made to catch a few specific invalid license characters (48e22cf). Because there can be a high number of invalid license characters, instead of trying to replace them all, this commit adds a try/catch statement to catch the AttributeError exception that gets thrown by license_expression when there is an invalid license character. Resolves #1203 Signed-off-by: Rose Judge <[email protected]>
1 parent cbea6d7 commit 700df46

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tern/formats/spdx/spdx_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@ def is_spdx_license_expression(license_data):
4848
'''Return True if the license is a valid SPDX license expression, else
4949
return False'''
5050
licensing = get_spdx_licensing()
51-
if ',' in license_data or '/' in license_data:
52-
license_data = license_data.replace(',', ' and ')
51+
not_allowed = [',', ';', '/', '&']
52+
if any(x in license_data for x in not_allowed):
53+
# Try to replace common invalid license characters
54+
license_data = license_data.replace(',', ' and')
5355
license_data = license_data.replace('/', '-')
54-
return licensing.validate(license_data).errors == []
56+
license_data = license_data.replace(';', '.')
57+
license_data = license_data.replace('&', 'and')
58+
try:
59+
return licensing.validate(license_data).errors == []
60+
# Catch any of the other invalid license chars here
61+
except AttributeError:
62+
return False
5563

5664
def get_package_license_declared(package_license_declared):
5765
'''Determines if the declared license string for a package or file is a

0 commit comments

Comments
 (0)