Skip to content

Commit 15a3438

Browse files
authored
Slice the fragment from the URL to 50 chars max #1669 (#1670)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent b9a842b commit 15a3438

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

scanpipe/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,10 +1209,11 @@ def add_input_source(self, download_url="", filename="", is_uploaded=False, tag=
12091209
if not download_url and not filename:
12101210
raise Exception("Provide at least a value for download_url or filename.")
12111211

1212-
# Add tag can be provided using the "#<fragment>" part of the URL
12131212
if download_url:
12141213
parsed_url = urlparse(download_url)
1215-
tag = parsed_url.fragment or tag
1214+
# Add tag can be provided using the "#<fragment>" part of the URL
1215+
if not tag and parsed_url.fragment:
1216+
tag = parsed_url.fragment[:50]
12161217

12171218
return InputSource.objects.create(
12181219
project=self,

scanpipe/tests/test_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,16 @@ def test_scanpipe_project_model_add_input_source(self):
510510
input_source = self.project1.add_input_source(download_url=url_with_fragment)
511511
self.assertEqual("tag_value", input_source.tag)
512512

513+
def test_scanpipe_project_model_add_input_source_tag_from_fragment(self):
514+
download_url = (
515+
"https://download.url/amqp-2.6.1-py2.py3-none-any.whl"
516+
"#sha256=aa7f313fb887c91f15474c1229907a04dac0b8135822d6603437803424c0aa59"
517+
)
518+
source = self.project1.add_input_source(download_url=download_url)
519+
self.assertEqual(
520+
"sha256=aa7f313fb887c91f15474c1229907a04dac0b813582", source.tag
521+
)
522+
513523
def test_scanpipe_project_model_add_downloads(self):
514524
file_location = self.data / "aboutcode" / "notice.NOTICE"
515525
copy_input(file_location, self.project1.tmp_path)

0 commit comments

Comments
 (0)