Skip to content

Commit

Permalink
fix: handle zero length strings
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Dec 9, 2024
1 parent 30b1cd1 commit 027a104
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions lib4sbom/data/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ def set_licenseinfoinfile(self, license_info):
self.file["licenseinfoinfile"] = [license_id]

def set_licensecomment(self, comment):
self.file["licensecomment"] = self._text(comment)
if len(comment) > 0:
self.file["licensecomment"] = self._text(comment)

def set_copyrighttext(self, text):
self.file["copyrighttext"] = self._text(text)
if len(text) > 0:
self.file["copyrighttext"] = self._text(text)

def set_comment(self, comment):
self.file["comment"] = self._text(comment)
if len(comment) > 0:
self.file["comment"] = self._text(comment)

def set_notice(self, notice):
self.file["notice"] = self._text(notice)
if len(notice) > 0:
self.file["notice"] = self._text(notice)

def set_contributor(self, name):
if len(name) > 0:
Expand Down
18 changes: 12 additions & 6 deletions lib4sbom/data/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def set_homepage(self, page):
self.package["homepage"] = page

def set_sourceinfo(self, info):
self.package["sourceinfo"] = self._text(info)
if len(info) > 0:
self.package["sourceinfo"] = self._text(info)

def set_filesanalysis(self, analysis):
self.package["filesanalysis"] = analysis
Expand Down Expand Up @@ -142,7 +143,8 @@ def set_licenselist(self, list):
self.package["licenselist"] = list

def set_licensecomments(self, comment):
self.package["licensecomments"] = self._text(comment)
if len(comment) > 0:
self.package["licensecomments"] = self._text(comment)

def set_licenseinfoinfiles(self, license_info):
# Validate license
Expand Down Expand Up @@ -265,16 +267,20 @@ def set_purl(self, purl_value):
self.set_externalreference("PACKAGE_MANAGER", "purl", purl_value)

def set_copyrighttext(self, text):
self.package["copyrighttext"] = self._text(text)
if len(text) > 0:
self.package["copyrighttext"] = self._text(text)

def set_comment(self, comment):
self.package["comment"] = self._text(comment)
if len(comment) > 0:
self.package["comment"] = self._text(comment)

def set_summary(self, summary):
self.package["summary"] = self._text(summary)
if len(summary) > 0:
self.package["summary"] = self._text(summary)

def set_description(self, description):
self.package["description"] = self._text(description)
if len(description) > 0:
self.package["description"] = self._text(description)

def set_evidence(self, evidence):
if "evidence" in self.package:
Expand Down
6 changes: 4 additions & 2 deletions lib4sbom/spdx/spdx_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def getRelationships(self):

def generateTag(self, tag, value):
if value is not None:
self.show(tag + ": " + value)
if len(value) > 0:
self.show(tag + ": " + value)
elif self.debug:
print(f"[ERROR] with value for {tag}")

Expand Down Expand Up @@ -204,7 +205,8 @@ def license_ident(self, license):

def _text(file, text_item):
if text_item not in ["NONE", "NOASSERTION"]:
return f"<text>{text_item}</text>"
if len(text_item) > 0:
return f"<text>{text_item}</text>"
return text_item

def _file_name(self, name):
Expand Down

0 comments on commit 027a104

Please sign in to comment.