Skip to content

Commit

Permalink
fix: handle : in filenames better
Browse files Browse the repository at this point in the history
Replace colon and backslash in filename to avoid a failure on Windows in
condensed_filepath function as already done in test_version_mapping
function

Fix #4401

Signed-off-by: Fabrice Fontaine <[email protected]>
  • Loading branch information
ffontaine committed Sep 6, 2024
1 parent cbf9f2b commit 7aff0ee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def teardown_class(cls):
shutil.rmtree(cls.package_test_dir)
shutil.rmtree(cls.mapping_test_dir)

def windows_fixup(self, filename):
"""Replace colon and backslash in filename to avoid a failure on Windows"""
return filename.replace(":", "_").replace("\\", "_")

def test_false_positive(self):
self.scanner.all_cves = []
with tempfile.NamedTemporaryFile(
Expand Down Expand Up @@ -148,10 +152,9 @@ def test_version_mapping(self, product, version, version_strings):
f"{'.'.join(list(product))}-{version}.out",
]
for filename in filenames:
# Replace colon and backslash in filename to avoid a failure on Windows
with tempfile.NamedTemporaryFile(
"w+b",
suffix=filename.replace(":", "_").replace("\\", "_"),
suffix=self.windows_fixup(filename),
dir=self.mapping_test_dir,
delete=False,
) as f:
Expand Down Expand Up @@ -234,7 +237,7 @@ def condensed_filepath(self, url, package_name):
dirpath.mkdir()
# Check if we've already made a condensed version of the file, if we
# have, we're done.
condensed_path = condensed_dir / (package_name + ".tar.gz")
condensed_path = condensed_dir / (self.windows_fixup(package_name) + ".tar.gz")
if condensed_path.is_file():
return str(condensed_path)
# Download the file if we don't have a condensed version of it and we
Expand Down

0 comments on commit 7aff0ee

Please sign in to comment.