Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/fosslight_util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def get_remote_refs(git_url: str):
re.IGNORECASE,
)
_CLARIFIED_MAJOR_ONLY_FULL = re.compile(r'^(?:v\.? ?)?(\d+)$', re.IGNORECASE)
# Maven / OSGi style: 1.1.7.7 (more than three numeric segments; not strict semver)
_PURE_DOT_NUMERIC_VERSION = re.compile(r'^\d+(\.\d+)+$')
# Two-part x.y not followed by .digit (avoids taking "1.2" from "1.2.3")
_CLARIFIED_TWO_IN_STR = re.compile(r'(\d+)\.(\d+)(?!\.\d)')
_CLARIFIED_MAJOR_IN_STR = re.compile(
Expand Down Expand Up @@ -350,6 +352,9 @@ def clarified_version_from_oss_version(oss_version: str) -> str:
s = (oss_version or "").strip()
if not s:
return ""
core = _strip_leading_v_prefix(s)
if _PURE_DOT_NUMERIC_VERSION.match(core):
return core
m = _BASE_SEMVER_FOR_CHECKOUT.match(s)
if m:
if m.group(3):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_download_version_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"/t/lodash-4.17.21.tgz",
"4.17.21",
),
# mvnrepository.com page URL (version is last path segment; four-part Maven version)
(
"https://mvnrepository.com/artifact/org.xerial.snappy/snappy-java/1.1.7.7",
"",
"1.1.7.7",
),
# Generic: path ends with /download but real version only in filename
(
"https://example.com/releases/download",
Expand Down Expand Up @@ -81,6 +87,8 @@ def test_oss_version_hint_from_wget_link(link, downloaded_file, expected_hint):
("2.31.0", "2.31.0"),
("4.17.21", "4.17.21"),
("1.1.4", "1.1.4"),
("1.1.7.7", "1.1.7.7"),
("v1.1.7.7", "1.1.7.7"),
("v3.28.3", "3.28.3"),
],
)
Expand All @@ -93,3 +101,10 @@ def test_github_archive_hint_then_clarified():
hint = _oss_version_hint_from_wget_link(link, "/t/v3.28.3.tar.gz")
assert hint == "v3.28.3"
assert clarified_version_from_oss_version(hint) == "3.28.3"


def test_mvnrepository_url_hint_then_clarified():
link = "https://mvnrepository.com/artifact/org.xerial.snappy/snappy-java/1.1.7.7"
hint = _oss_version_hint_from_wget_link(link, "")
assert hint == "1.1.7.7"
assert clarified_version_from_oss_version(hint) == "1.1.7.7"
Loading