Skip to content

Commit

Permalink
Use "gem" instead of "rubygems" to match purl spec (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: tdruez <489057+tdruez@users.noreply.github.com>
  • Loading branch information
juspence and tdruez authored Dec 8, 2023
1 parent baf0c61 commit bdbc8c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/packageurl/contrib/purl2url.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def build_gitlab_repo_url(purl):
return f"https://gitlab.com/{namespace}/{name}"


@repo_router.route("pkg:rubygems/.*")
@repo_router.route("pkg:gem/.*")
def build_rubygems_repo_url(purl):
"""
Return a rubygems repo URL from the `purl` string.
Expand Down Expand Up @@ -291,7 +291,7 @@ def build_cargo_download_url(purl):
return f"https://crates.io/api/v1/crates/{name}/{version}/download"


@download_router.route("pkg:rubygems/.*")
@download_router.route("pkg:gem/.*")
def build_rubygems_download_url(purl):
"""
Return a rubygems download URL from the `purl` string.
Expand Down
2 changes: 1 addition & 1 deletion src/packageurl/contrib/url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def build_rubygems_purl(uri):
rubygems_pattern = (
r"^https?://rubygems.org/(downloads|gems)/(?P<name>.+)-(?P<version>.+)(\.gem)$"
)
return purl_from_pattern("rubygems", rubygems_pattern, uri)
return purl_from_pattern("gem", rubygems_pattern, uri)


# https://pypi.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz
Expand Down
26 changes: 13 additions & 13 deletions tests/contrib/data/url2purl.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@
"https://www.npmjs.org/package/": null,
"http://rubygems.org/downloads/": null,
"http://rubygems.org/downloads/macaddr-1.6.1": null,
"http://rubygems.org/downloads/macaddr-1.6.1.gem": "pkg:rubygems/macaddr@1.6.1",
"http://rubygems.org/downloads/open4-1.3.0.gem": "pkg:rubygems/open4@1.3.0",
"https://rubygems.org/downloads/actionmailer-4.0.3.gem": "pkg:rubygems/actionmailer@4.0.3",
"https://rubygems.org/downloads/activerecord-deprecated_finders-1.0.3.gem": "pkg:rubygems/activerecord-deprecated_finders@1.0.3",
"https://rubygems.org/downloads/ejs-1.1.1.gem": "pkg:rubygems/ejs@1.1.1",
"https://rubygems.org/downloads/eventmachine-0.12.11.cloudfoundry.3.gem": "pkg:rubygems/eventmachine@0.12.11.cloudfoundry.3",
"https://rubygems.org/downloads/ffi-1.9.3.gem": "pkg:rubygems/ffi@1.9.3",
"https://rubygems.org/downloads/jwt-0.1.8.gem": "pkg:rubygems/jwt@0.1.8",
"https://rubygems.org/downloads/ref-1.0.5.gem": "pkg:rubygems/ref@1.0.5",
"https://rubygems.org/downloads/talentbox-delayed_job_sequel-4.0.0.gem": "pkg:rubygems/talentbox-delayed_job_sequel@4.0.0",
"https://rubygems.org/downloads/unf-0.1.3.gem": "pkg:rubygems/unf@0.1.3",
"https://rubygems.org/downloads/yajl-ruby-1.2.0.gem": "pkg:rubygems/yajl-ruby@1.2.0",
"https://rubygems.org/gems/i18n-js-3.0.11.gem": "pkg:rubygems/i18n-js@3.0.11",
"http://rubygems.org/downloads/macaddr-1.6.1.gem": "pkg:gem/macaddr@1.6.1",
"http://rubygems.org/downloads/open4-1.3.0.gem": "pkg:gem/open4@1.3.0",
"https://rubygems.org/downloads/actionmailer-4.0.3.gem": "pkg:gem/actionmailer@4.0.3",
"https://rubygems.org/downloads/activerecord-deprecated_finders-1.0.3.gem": "pkg:gem/activerecord-deprecated_finders@1.0.3",
"https://rubygems.org/downloads/ejs-1.1.1.gem": "pkg:gem/ejs@1.1.1",
"https://rubygems.org/downloads/eventmachine-0.12.11.cloudfoundry.3.gem": "pkg:gem/eventmachine@0.12.11.cloudfoundry.3",
"https://rubygems.org/downloads/ffi-1.9.3.gem": "pkg:gem/ffi@1.9.3",
"https://rubygems.org/downloads/jwt-0.1.8.gem": "pkg:gem/jwt@0.1.8",
"https://rubygems.org/downloads/ref-1.0.5.gem": "pkg:gem/ref@1.0.5",
"https://rubygems.org/downloads/talentbox-delayed_job_sequel-4.0.0.gem": "pkg:gem/talentbox-delayed_job_sequel@4.0.0",
"https://rubygems.org/downloads/unf-0.1.3.gem": "pkg:gem/unf@0.1.3",
"https://rubygems.org/downloads/yajl-ruby-1.2.0.gem": "pkg:gem/yajl-ruby@1.2.0",
"https://rubygems.org/gems/i18n-js-3.0.11.gem": "pkg:gem/i18n-js@3.0.11",
"https://pypi.org/packages/source/z/zc.recipe.egg/zc.recipe.egg-2.0.0.tar.gz": "pkg:pypi/zc.recipe.egg@2.0.0",
"https://pypi.org/project/widgetsnbextension": "pkg:pypi/widgetsnbextension",
"https://pypi.org/project/widgetsnbextension/3.0.7/": "pkg:pypi/widgetsnbextension@3.0.7",
Expand Down
12 changes: 6 additions & 6 deletions tests/contrib/test_purl2url.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_purl2url_get_repo_url():
"pkg:github/tg1999": None,
"pkg:cargo/rand@0.7.2": "https://crates.io/crates/rand/0.7.2",
"pkg:cargo/abc": "https://crates.io/crates/abc",
"pkg:rubygems/bundler@2.3.23": "https://rubygems.org/gems/bundler/versions/2.3.23",
"pkg:gem/package-name": None,
"pkg:gem/bundler@2.3.23": "https://rubygems.org/gems/bundler/versions/2.3.23",
"pkg:rubygems/package-name": None,
"pkg:bitbucket/birkenfeld/pygments-main": "https://bitbucket.org/birkenfeld/pygments-main",
"pkg:bitbucket/birkenfeld/pygments-main@244fd47e07d1014f0aed9c": "https://bitbucket.org/birkenfeld/pygments-main",
"pkg:bitbucket/birkenfeld/pygments-main@master#views": "https://bitbucket.org/birkenfeld/pygments-main",
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_purl2url_get_download_url():
purls_url = {
# Generated
"pkg:cargo/rand@0.7.2": "https://crates.io/api/v1/crates/rand/0.7.2/download",
"pkg:rubygems/bundler@2.3.23": "https://rubygems.org/downloads/bundler-2.3.23.gem",
"pkg:gem/bundler@2.3.23": "https://rubygems.org/downloads/bundler-2.3.23.gem",
"pkg:npm/is-npm@1.0.0": "http://registry.npmjs.org/is-npm/-/is-npm-1.0.0.tgz",
"pkg:hackage/cli-extras@0.2.0.0": "https://hackage.haskell.org/package/cli-extras-0.2.0.0/cli-extras-0.2.0.0.tar.gz",
"pkg:nuget/System.Text.Json@6.0.6": "https://www.nuget.org/api/v2/package/System.Text.Json/6.0.6",
Expand All @@ -89,7 +89,7 @@ def test_purl2url_get_download_url():
# Not-supported
"pkg:github/tg1999/fetchcode": None,
"pkg:cargo/abc": None,
"pkg:gem/package-name": None,
"pkg:rubygems/package-name": None,
"pkg:bitbucket/birkenfeld": None,
"pkg:pypi/sortedcontainers@2.4.0": None,
"pkg:golang/xorm.io/xorm@v0.8.2": None,
Expand All @@ -106,7 +106,7 @@ def test_purl2url_get_inferred_urls():
"https://crates.io/crates/rand/0.7.2",
"https://crates.io/api/v1/crates/rand/0.7.2/download",
],
"pkg:rubygems/bundler@2.3.23": [
"pkg:gem/bundler@2.3.23": [
"https://rubygems.org/gems/bundler/versions/2.3.23",
"https://rubygems.org/downloads/bundler-2.3.23.gem",
],
Expand All @@ -129,7 +129,7 @@ def test_purl2url_get_inferred_urls():
"https://gitlab.com/tg1999/firebase/-/archive/1a122122/firebase-1a122122.tar.gz",
],
"pkg:pypi/sortedcontainers@2.4.0": ["https://pypi.org/project/sortedcontainers/2.4.0/"],
"pkg:gem/package-name": [],
"pkg:rubygems/package-name": [],
"pkg:bitbucket/birkenfeld": [],
}

Expand Down

0 comments on commit bdbc8c8

Please sign in to comment.