Skip to content

Replace spaces with '+' in github repo_url and download_url #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions src/packageurl/contrib/purl2url.py
Original file line number Diff line number Diff line change
@@ -40,9 +40,9 @@ def get_repo_download_url_by_package_type(
raise ValueError("Only zip and tar.gz extensions are supported")

download_url_by_type = {
"github": f"https://github.com/{namespace}/{name}/archive/{version}.{archive_extension}",
"bitbucket": f"https://bitbucket.org/{namespace}/{name}/get/{version}.{archive_extension}",
"gitlab": f"https://gitlab.com/{namespace}/{name}/-/archive/{version}/{name}-{version}.{archive_extension}",
"github": f"https://github.com/{namespace}/{name}/archive/{version}.{archive_extension}".replace(" ", "+"),
"bitbucket": f"https://bitbucket.org/{namespace}/{name}/get/{version}.{archive_extension}".replace(" ", "+"),
"gitlab": f"https://gitlab.com/{namespace}/{name}/-/archive/{version}/{name}-{version}.{archive_extension}".replace(" ", "+"),
}
return download_url_by_type.get(type)

@@ -153,6 +153,8 @@ def build_github_repo_url(purl):
version_prefix = qualifiers.get("version_prefix", "")
repo_url = f"{repo_url}/tree/{version_prefix}{version}"

repo_url = repo_url.replace(" ", "+")

return repo_url


2 changes: 2 additions & 0 deletions tests/contrib/test_purl2url.py
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ def test_purl2url_get_repo_url():
"pkg:golang/gopkg.in/[email protected]": "https://pkg.go.dev/gopkg.in/[email protected]",
"pkg:cocoapods/[email protected]": "https://cocoapods.org/pods/AFNetworking",
"pkg:cocoapods/[email protected]": "https://cocoapods.org/pods/MapsIndoors",
"pkg:github/facebook/[email protected]%20f4e9df48": "https://github.com/facebook/sapling/tree/0.2.20240718-145624+f4e9df48"
}

for purl, url in purls_url.items():
@@ -99,6 +100,7 @@ def test_purl2url_get_download_url():
"pkg:bitbucket/robeden/trove?download_url=https://bitbucket.org/robeden/trove/downloads/trove-3.0.3.zip": "https://bitbucket.org/robeden/trove/downloads/trove-3.0.3.zip",
"pkg:sourceforge/zclasspath?download_url=http://master.dl.sourceforge.net/project/zclasspath/maven2/org/zclasspath/zclasspath/1.5/zclasspath-1.5.jar": "http://master.dl.sourceforge.net/project/zclasspath/maven2/org/zclasspath/zclasspath/1.5/zclasspath-1.5.jar",
"pkg:pypi/[email protected]?download_url=https://files.pythonhosted.org/packages/87/44/0fa8e9d0cccb8eb86fc1b5170208229dc6d6e9fd6e57ea1fe19cbeea68f5/aboutcode_toolkit-3.4.0rc1-py2.py3-none-any.whl": "https://files.pythonhosted.org/packages/87/44/0fa8e9d0cccb8eb86fc1b5170208229dc6d6e9fd6e57ea1fe19cbeea68f5/aboutcode_toolkit-3.4.0rc1-py2.py3-none-any.whl",
"pkg:github/facebook/[email protected]%20f4e9df48": "https://github.com/facebook/sapling/archive/0.2.20240718-145624+f4e9df48.tar.gz",
# Not-supported
"pkg:github/tg1999/fetchcode": None,
"pkg:cargo/abc": None,