@@ -879,6 +879,7 @@ def hydrate(self, fields):
879879 """
880880 errors = []
881881 seen_fields = {}
882+ illegal_name_list = []
882883
883884 for name , value in fields :
884885 orig_name = name
@@ -916,10 +917,16 @@ def hydrate(self, fields):
916917
917918 # A custom field
918919 # is the name valid?
920+ if not is_valid_name (name ):
921+ if not name in illegal_name_list :
922+ illegal_name_list .append (name )
923+ continue
924+ """
919925 illegal_name_error = validate_field_name(name)
920926 if illegal_name_error:
921- errors .append (illegal_name_error )
927+ errors.append(illegal_name_list )
922928 continue
929+ """
923930
924931 msg = 'Field %(orig_name)s is a custom field.'
925932 errors .append (Error (INFO , msg % locals ()))
@@ -945,6 +952,10 @@ def hydrate(self, fields):
945952 msg = 'Internal error with custom field: %(name)r: %(value)r.'
946953 errors .append (Error (CRITICAL , msg % locals ()))
947954
955+ if illegal_name_list :
956+ msg = ('Field name: %(illegal_name_list)r contains illegal name characters: '
957+ '0 to 9, a to z, A to Z and _. (or empty spaces) and is ignored.' )
958+ errors .append (Error (CRITICAL , msg % locals ()))
948959 return errors
949960
950961 def process (self , fields , about_file_path , running_inventory = False ,
@@ -1034,7 +1045,7 @@ def load_dict(self, fields_dict, base_dir, scancode=False, from_attrib=False, ru
10341045
10351046 for key , value in fields :
10361047 if not value :
1037- # never return empty or absent fieds
1048+ # never return empty or absent fields
10381049 continue
10391050 if key == u'licenses' :
10401051 # FIXME: use a license object instead
@@ -1147,11 +1158,14 @@ def dumps(self, licenses_dict=None):
11471158 if licenses_dict and lic_key in licenses_dict :
11481159 lic_dict ['key' ] = lic_key
11491160 lic_name , lic_filename , lic_context , lic_url , spdx_lic_key = licenses_dict [lic_key ]
1150-
1151- lic_dict ['name' ] = lic_name
1152- lic_dict ['file' ] = lic_filename
1153- lic_dict ['url' ] = lic_url
1154- lic_dict ['spdx_license_key' ] = spdx_lic_key
1161+ if lic_name :
1162+ lic_dict ['name' ] = lic_name
1163+ if lic_filename :
1164+ lic_dict ['file' ] = lic_filename
1165+ if lic_url :
1166+ lic_dict ['url' ] = lic_url
1167+ if spdx_lic_key :
1168+ lic_dict ['spdx_license_key' ] = spdx_lic_key
11551169
11561170 # Remove the license information if it has been handled
11571171 lic_key_copy .remove (lic_key )
@@ -1161,6 +1175,8 @@ def dumps(self, licenses_dict=None):
11611175 license_url .remove (lic_url )
11621176 if lic_filename in license_file :
11631177 license_file .remove (lic_filename )
1178+ if spdx_lic_key in spdx_license_key :
1179+ spdx_license_key .remove (spdx_lic_key )
11641180 lic_dict_list .append (lic_dict )
11651181
11661182 # Handle license information that have not been handled.
@@ -1277,7 +1293,6 @@ def dump_lic(self, location, license_dict):
12771293 loc = util .to_posix (location )
12781294 parent = posixpath .dirname (loc )
12791295 license_key_name_context_url = []
1280- err = ''
12811296
12821297 if not posixpath .exists (parent ):
12831298 os .makedirs (add_unc (parent ))
@@ -1288,20 +1303,26 @@ def dump_lic(self, location, license_dict):
12881303 self .license_key .present = True
12891304 if not special_char_in_expression :
12901305 for lic_key in lic_list :
1291- try :
1292- if license_dict [lic_key ]:
1293- license_path = posixpath .join (parent , lic_key )
1294- license_path += u'.LICENSE'
1295- license_path = add_unc (license_path )
1296- license_name , license_filename , license_context , license_url , spdx_license_key = license_dict [lic_key ]
1297- license_info = (lic_key , license_name , license_filename , license_context , license_url , spdx_license_key )
1298- license_key_name_context_url .append (license_info )
1299- with io .open (license_path , mode = 'w' , encoding = 'utf-8' , newline = '\n ' , errors = 'replace' ) as lic :
1300- lic .write (license_context )
1301- except Exception as e :
1302- err = Error (ERROR , 'Invalid license: ' + str (e ))
1303-
1304- return license_key_name_context_url , err
1306+ license_name = ''
1307+ license_filename = ''
1308+ license_context = ''
1309+ license_url = ''
1310+ spdx_license_key = ''
1311+ if lic_key in license_dict :
1312+ license_path = posixpath .join (parent , lic_key )
1313+ license_path += u'.LICENSE'
1314+ license_path = add_unc (license_path )
1315+ license_name , license_filename , license_context , license_url , spdx_license_key = license_dict [lic_key ]
1316+ license_info = (lic_key , license_name , license_filename , license_context , license_url , spdx_license_key )
1317+ license_key_name_context_url .append (license_info )
1318+ with io .open (license_path , mode = 'w' , encoding = 'utf-8' , newline = '\n ' , errors = 'replace' ) as lic :
1319+ lic .write (license_context )
1320+ else :
1321+ # Invalid license issue is already handled
1322+ license_info = (lic_key , license_name , license_filename , license_context , license_url , spdx_license_key )
1323+ license_key_name_context_url .append (license_info )
1324+
1325+ return license_key_name_context_url
13051326
13061327
13071328def collect_inventory (location ):
@@ -1324,7 +1345,7 @@ def collect_inventory(location):
13241345 msg = (about_file_path + ": " + message )
13251346 errors .append (Error (severity , msg ))
13261347 abouts .append (about )
1327- return unique ( errors ) , abouts
1348+ return errors , abouts
13281349
13291350
13301351def collect_abouts_license_expression (location ):
0 commit comments