Skip to content

Commit 17a6d41

Browse files
authored
fix: handle : in filenames better (#4418)
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]>
1 parent cbf9f2b commit 17a6d41

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/test_scanner.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def teardown_class(cls):
8383
shutil.rmtree(cls.package_test_dir)
8484
shutil.rmtree(cls.mapping_test_dir)
8585

86+
def windows_fixup(self, filename):
87+
"""Replace colon and backslash in filename to avoid a failure on Windows"""
88+
return filename.replace(":", "_").replace("\\", "_")
89+
8690
def test_false_positive(self):
8791
self.scanner.all_cves = []
8892
with tempfile.NamedTemporaryFile(
@@ -148,10 +152,9 @@ def test_version_mapping(self, product, version, version_strings):
148152
f"{'.'.join(list(product))}-{version}.out",
149153
]
150154
for filename in filenames:
151-
# Replace colon and backslash in filename to avoid a failure on Windows
152155
with tempfile.NamedTemporaryFile(
153156
"w+b",
154-
suffix=filename.replace(":", "_").replace("\\", "_"),
157+
suffix=self.windows_fixup(filename),
155158
dir=self.mapping_test_dir,
156159
delete=False,
157160
) as f:
@@ -234,7 +237,7 @@ def condensed_filepath(self, url, package_name):
234237
dirpath.mkdir()
235238
# Check if we've already made a condensed version of the file, if we
236239
# have, we're done.
237-
condensed_path = condensed_dir / (package_name + ".tar.gz")
240+
condensed_path = condensed_dir / (self.windows_fixup(package_name) + ".tar.gz")
238241
if condensed_path.is_file():
239242
return str(condensed_path)
240243
# Download the file if we don't have a condensed version of it and we

0 commit comments

Comments
 (0)