@@ -149,12 +149,13 @@ def spdx_parse(file):
149149 start = time .process_time ()
150150 try :
151151 document : Document = parse_file (file )
152- print ('SPDX parsing took {:.2f}s' .format (time .process_time () - start ))
153- return (document )
154152 except SPDXParsingError :
155153 logging .exception ("Failed to parse spdx file" )
156154 sys .exit (1 )
157155
156+ print ('SPDX parsing took {:.2f}s' .format (time .process_time () - start ))
157+ return (document )
158+
158159# Validates the SPDX file. Logs all validation messages as warnings.
159160# Input: SPDX document object
160161def spdx_validate (document ):
@@ -198,7 +199,6 @@ def poll_for_upload(sbom_name):
198199 }
199200 cls = bd .get_resource ('codeLocations' , params = params )
200201 for cl in cls :
201- print (cl ['name' ])
202202 # Force exact match of: spdx_doc_name + " spdx/sbom"
203203 # BD appends the "spdx/sbom" string to the name.
204204 if cl ['name' ] != sbom_name + " spdx/sbom" :
@@ -559,7 +559,7 @@ def main():
559559 # Upload the provided SBOM
560560 upload_sbom_file (args .spdx_file , args .project_name , args .version_name )
561561
562- # Wait for scan completeion . Will exit if it fails.
562+ # Wait for scan completion . Will exit if it fails.
563563 poll_for_upload (document .creation_info .name )
564564 # Also exits on failure. This may be somewhat redundant.
565565 poll_for_sbom_scan (document .creation_info .name , version )
@@ -591,14 +591,24 @@ def main():
591591 # We hope we'll have an external reference (pURL), but we might not.
592592 extref = None
593593 purlmatch = False
594+
595+ if package .name == "" :
596+ # Strange case where the package name is empty. Skip it.
597+ logging .warning ("WARNING: package name empty, skipping" )
598+ continue
599+ # Trim any odd leading/trailing space or newlines
600+ package .name = package .name .strip ()
601+
594602 # matchname/matchver can change, depending on the KB lookup step.
595603 # These are stored separately to keep the original names handy
596604 matchname = package .name
597- if package .version is None :
605+ if package .version is None or package . version == "" :
598606 # Default in case one is not specified in SPDX
599607 package .version = "UNKNOWN"
608+ package .version = package .version .strip ()
600609 matchver = package .version
601- print (f"Processing SPDX package: { matchname } version: { matchver } ...." )
610+ print (f"Processing SPDX package: { matchname } version: { matchver } ..." )
611+
602612 # Tracking unique package name + version combos from spdx file
603613 packages [matchname + matchver ] = packages .get (matchname + matchver , 0 ) + 1
604614
@@ -643,6 +653,8 @@ def main():
643653 # - Do we need to add a version to an existing custom component?
644654 nomatch += 1
645655 print (f" Not present in BOM: { matchname } { matchver } " )
656+
657+ # Missing component data to write to a file for reference
646658 comp_data = {
647659 "name" : package .name ,
648660 "spdx_id" : package .spdx_id ,
0 commit comments