Skip to content

Commit 3513ff1

Browse files
committed
relatives links fix
This a fix for issue It adds the ability to handle relative links first check if a link is relative and joining to the full package url Signed-off-by: Georgios Mathioudakis [email protected]
1 parent 1831e01 commit 3513ff1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/python_inspector/utils_pypi.py

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from packvers import tags as packaging_tags
3131
from packvers import version as packaging_version
3232
from packvers.specifiers import SpecifierSet
33+
from urllib.parse import urljoin
3334

3435
from python_inspector import DEFAULT_PYTHON_VERSION
3536
from python_inspector import utils_pip_compatibility_tags
@@ -1593,8 +1594,15 @@ def fetch_links(
15931594
for anchor_tag in anchor_tags:
15941595
python_requires = None
15951596
url, _, _sha256 = anchor_tag["href"].partition("#sha256=")
1597+
if url.startswith(".."):
1598+
# Handle relative links
1599+
url = urljoin(package_url, url)
15961600
if "data-requires-python" in anchor_tag.attrs:
15971601
python_requires = anchor_tag.attrs["data-requires-python"]
1602+
# Check if the link is a relative URL
1603+
if not url.startswith(("http://", "https://")):
1604+
base_url = "/".join(package_url.split("/")[:-1]) # Extract base URL
1605+
url = urljoin(base_url, url) # Resolve relative URL
15981606
links.append(Link(url=url, python_requires=python_requires))
15991607
# TODO: keep sha256
16001608
return links

0 commit comments

Comments
 (0)