Skip to content

Commit 44217a5

Browse files
committed
Handle licenses with empty license test in SPDX library
Signed-off-by: tdruez <[email protected]>
1 parent 5f985e2 commit 44217a5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

scanpipe/pipes/spdx.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,14 @@ class ExtractedLicensingInfo:
280280

281281
def as_dict(self):
282282
"""Return the data as a serializable dict."""
283+
if self.extracted_text.strip():
284+
extracted_text = self.extracted_text
285+
else:
286+
extracted_text = "NOASSERTION"
287+
283288
required_data = {
284289
"licenseId": self.license_id,
285-
"extractedText": self.extracted_text,
290+
"extractedText": extracted_text,
286291
}
287292

288293
optional_data = {

scanpipe/tests/pipes/test_spdx.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,15 @@ def test_spdx_extracted_licensing_info_as_dict(self):
318318
licensing_info = spdx.ExtractedLicensingInfo(**self.licensing_info_data)
319319
assert self.licensing_info_spdx_data == licensing_info.as_dict()
320320

321+
def test_spdx_extracted_licensing_info_empty_extracted_text(self):
322+
licensing_info = spdx.ExtractedLicensingInfo(
323+
**{
324+
"license_id": "LicenseRef-1",
325+
"extracted_text": " ",
326+
}
327+
)
328+
assert "NOASSERTION" == licensing_info.as_dict()["extractedText"]
329+
321330
def test_spdx_extracted_licensing_info_from_data(self):
322331
assert spdx.ExtractedLicensingInfo.from_data({})
323332
licensing_info = spdx.ExtractedLicensingInfo.from_data(

0 commit comments

Comments
 (0)