@@ -1194,7 +1194,7 @@ def load_dict(self, fields_dict, base_dir, scancode=False, from_attrib=False, ru
11941194 lic_key_exp_list = []
11951195 lic_score_list = []
11961196 for lic in lic_list :
1197- _char , lic_keys = parse_license_expression (
1197+ _char , lic_keys , _invalid_lic_exp = parse_license_expression (
11981198 lic ['lic_exp' ])
11991199 lic_key_list .append (lic_keys )
12001200 # for lic_key in lic_keys:
@@ -1327,7 +1327,7 @@ def dumps(self, licenses_dict=None):
13271327 # and get the parsed license key
13281328 if 'license_expression' in data :
13291329 if not license_key and data ['license_expression' ]:
1330- _spec_char , lic_list = parse_license_expression (
1330+ _spec_char , lic_list , _invalid_lic_exp = parse_license_expression (
13311331 data ['license_expression' ])
13321332 license_key = lic_list
13331333
@@ -1501,11 +1501,11 @@ def dump_lic(self, location, license_dict):
15011501 os .makedirs (add_unc (parent ))
15021502
15031503 if self .license_expression .present :
1504- special_char_in_expression , lic_list = parse_license_expression (
1504+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
15051505 self .license_expression .value )
15061506 self .license_key .value = lic_list
15071507 self .license_key .present = True
1508- if not special_char_in_expression :
1508+ if not special_char_in_expression and not invalid_lic_exp :
15091509 for lic_key in lic_list :
15101510 license_name = ''
15111511 license_filename = ''
@@ -1905,11 +1905,15 @@ def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, a
19051905
19061906 if not about .license_expression .value and about .spdx_license_expression .value :
19071907 lic_exp_value = ""
1908- special_char_in_expression , lic_list = parse_license_expression (
1908+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
19091909 about .spdx_license_expression .value )
1910- if special_char_in_expression :
1911- msg = (about .about_file_path + u": The following character(s) cannot be in the spdx_license_expression: " +
1912- str (special_char_in_expression ))
1910+ if special_char_in_expression or invalid_lic_exp :
1911+ if special_char_in_expression :
1912+ msg = (about .about_file_path + u": The following character(s) cannot be in the spdx_license_expression: " +
1913+ str (special_char_in_expression ))
1914+ else :
1915+ msg = (about .about_file_path + u": This spdx_license_expression is invalid: " +
1916+ str (invalid_lic_exp ))
19131917 errors .append (Error (ERROR , msg ))
19141918 else :
19151919 spdx_lic_exp_segment = about .spdx_license_expression .value .split ()
@@ -1925,11 +1929,15 @@ def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, a
19251929 about .license_expression .present = True
19261930
19271931 if about .license_expression .value :
1928- special_char_in_expression , lic_list = parse_license_expression (
1932+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
19291933 about .license_expression .value )
1930- if special_char_in_expression :
1931- msg = (about .about_file_path + u": The following character(s) cannot be in the license_expression: " +
1932- str (special_char_in_expression ))
1934+ if special_char_in_expression or invalid_lic_exp :
1935+ if special_char_in_expression :
1936+ msg = (about .about_file_path + u": The following character(s) cannot be in the license_expression: " +
1937+ str (special_char_in_expression ))
1938+ else :
1939+ msg = (about .about_file_path + u": This license_expression is invalid: " +
1940+ str (invalid_lic_exp ))
19331941 errors .append (Error (ERROR , msg ))
19341942 else :
19351943 for lic_key in lic_list :
@@ -2027,11 +2035,15 @@ def convert_spdx_expression_to_lic_expression(spdx_key, spdx_lic_dict):
20272035def parse_license_expression (lic_expression ):
20282036 licensing = Licensing ()
20292037 lic_list = []
2038+ invalid_lic_exp = ''
20302039 special_char = detect_special_char (lic_expression )
20312040 if not special_char :
20322041 # Parse the license expression and save it into a list
2033- lic_list = licensing .license_keys (lic_expression )
2034- return special_char , lic_list
2042+ try :
2043+ lic_list = licensing .license_keys (lic_expression )
2044+ except :
2045+ invalid_lic_exp = lic_expression
2046+ return special_char , lic_list , invalid_lic_exp
20352047
20362048
20372049def detect_special_char (expression ):
0 commit comments