From 3513ff175840d1e5d3743a48c234d402063a5e79 Mon Sep 17 00:00:00 2001 From: mathioud Date: Thu, 15 Jun 2023 09:46:22 +0200 Subject: [PATCH] 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 georgios.mathioudakis@here.com --- src/python_inspector/utils_pypi.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/python_inspector/utils_pypi.py b/src/python_inspector/utils_pypi.py index df14920..33a2454 100644 --- a/src/python_inspector/utils_pypi.py +++ b/src/python_inspector/utils_pypi.py @@ -30,6 +30,7 @@ from packvers import tags as packaging_tags from packvers import version as packaging_version from packvers.specifiers import SpecifierSet +from urllib.parse import urljoin from python_inspector import DEFAULT_PYTHON_VERSION from python_inspector import utils_pip_compatibility_tags @@ -1593,8 +1594,15 @@ def fetch_links( for anchor_tag in anchor_tags: python_requires = None url, _, _sha256 = anchor_tag["href"].partition("#sha256=") + if url.startswith(".."): + # Handle relative links + url = urljoin(package_url, url) if "data-requires-python" in anchor_tag.attrs: python_requires = anchor_tag.attrs["data-requires-python"] + # Check if the link is a relative URL + if not url.startswith(("http://", "https://")): + base_url = "/".join(package_url.split("/")[:-1]) # Extract base URL + url = urljoin(base_url, url) # Resolve relative URL links.append(Link(url=url, python_requires=python_requires)) # TODO: keep sha256 return links