Skip to content

Commit f1102db

Browse files
committed
fix: support case-insensitive extensions in resolve pipes #2360
Signed-off-by: Rucha0901 <imt_2025071@iiitm.ac.in>
1 parent c9387b4 commit f1102db

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎scanpipe/pipes/resolve.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def get_spdx_document_from_file(input_location):
451451
"""Return the loaded SPDX document from the `input_location` file."""
452452
input_path = Path(input_location)
453453

454-
if str(input_path).endswith((".yml", ".yaml")):
454+
if input_path.suffix.lower() in (".yml", ".yaml"):
455455
spdx_document = saneyaml.load(input_path.read_text())
456456
else:
457457
spdx_document = json.loads(input_path.read_text())
@@ -507,7 +507,7 @@ def get_default_package_type(input_location):
507507
if input_location.endswith(("bom.json", ".cdx.json", "bom.xml", ".cdx.xml")):
508508
return "cyclonedx"
509509

510-
if input_location.endswith((".json", ".xml", ".yml", ".yaml")):
510+
if input_location.lower().endswith((".json", ".xml", ".yml", ".yaml")):
511511
if cyclonedx.is_cyclonedx_bom(input_location):
512512
return "cyclonedx"
513513
if spdx.is_spdx_document(input_location):

‎scanpipe/tests/pipes/test_resolve.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def test_scanpipe_pipes_resolve_get_default_package_type(self):
7676
input_location = self.data / "cyclonedx" / "laravel-7.12.0" / "bom.1.7.json"
7777
self.assertEqual("cyclonedx", resolve.get_default_package_type(input_location))
7878

79+
with tempfile.TemporaryDirectory() as tmp_dir:
80+
upper_json = Path(tmp_dir) / "spdx_doc.JSON"
81+
upper_json.write_text('{"SPDXID": "SPDXRef-DOCUMENT"}')
82+
self.assertEqual("spdx", resolve.get_default_package_type(upper_json))
83+
84+
upper_yml = Path(tmp_dir) / "spdx_doc.YML"
85+
upper_yml.write_text("SPDXID: SPDXRef-DOCUMENT\n")
86+
self.assertEqual("spdx", resolve.get_default_package_type(upper_yml))
87+
7988
def test_scanpipe_pipes_resolve_set_license_expression(self):
8089
extracted_license_statement = {"license": "MIT"}
8190
data = resolve.set_license_expression(
@@ -289,6 +298,14 @@ def test_scanpipe_pipes_resolve_get_spdx_document_from_file(self):
289298
self.assertEqual("SPDXRef-DOCUMENT", spdx_document["SPDXID"])
290299
self.assertEqual("SPDX-2.2", spdx_document["spdxVersion"])
291300

301+
with tempfile.TemporaryDirectory() as tmp_dir:
302+
upper_yml = Path(tmp_dir) / "test.YML"
303+
upper_yml.write_text(input_location.read_text())
304+
spdx_document = resolve.get_spdx_document_from_file(upper_yml)
305+
self.assertIsInstance(spdx_document, dict)
306+
self.assertEqual("SPDXRef-DOCUMENT", spdx_document["SPDXID"])
307+
self.assertEqual("SPDX-2.2", spdx_document["spdxVersion"])
308+
292309
def test_scanpipe_pipes_resolve_spdx_package_to_package_data(self):
293310
p1 = Project.objects.create(name="Analysis")
294311
package = pipes.update_or_create_package(p1, package_data1)

0 commit comments

Comments
 (0)