Skip to content
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

feat: add missing purl types #43

Merged
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
28 changes: 26 additions & 2 deletions packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ var (
// special treatment during parsing.
// https://github.com/package-url/purl-spec#known-purl-types
var (
// TypeAlpm is a pkg:alpm purl.
TypeAlpm = "alpm"
mcombuechen marked this conversation as resolved.
Show resolved Hide resolved
// TypeApk is a pkg:apk purl.
TypeApk = "apk"
// TypeBitbucket is a pkg:bitbucket purl.
TypeBitbucket = "bitbucket"
// TypeCocoapods is a pkg:cocoapods purl.
Expand Down Expand Up @@ -81,12 +85,16 @@ var (
TypeNPM = "npm"
// TypeNuget is a pkg:nuget purl.
TypeNuget = "nuget"
// TypeQPKG is a pkg:qpkg purl.
TypeQpkg = "qpkg"
// TypeOCI is a pkg:oci purl
TypeOCI = "oci"
// TypePyPi is a pkg:pypi purl.
TypePyPi = "pypi"
// TypeRPM is a pkg:rpm purl.
TypeRPM = "rpm"
// TypeSWID is pkg:swid purl
TypeSWID = "swid"
// TypeSwift is pkg:swift purl
TypeSwift = "swift"
// TypeHuggingface is pkg:huggingface purl.
Expand Down Expand Up @@ -348,7 +356,16 @@ func FromString(purl string) (PackageURL, error) {
// See https://github.com/package-url/purl-spec#known-purl-types
func typeAdjustNamespace(purlType, ns string) string {
switch purlType {
case TypeBitbucket, TypeDebian, TypeGithub, TypeGolang, TypeNPM, TypeRPM, TypeComposer:
case TypeAlpm,
TypeApk,
TypeBitbucket,
TypeComposer,
TypeDebian,
TypeGithub,
TypeGolang,
TypeNPM,
TypeRPM,
TypeQpkg:
return strings.ToLower(ns)
}
return ns
Expand All @@ -359,7 +376,14 @@ func typeAdjustNamespace(purlType, ns string) string {
func typeAdjustName(purlType, name string, qualifiers Qualifiers) string {
quals := qualifiers.Map()
switch purlType {
case TypeBitbucket, TypeDebian, TypeGithub, TypeGolang, TypeNPM, TypeComposer:
case TypeAlpm,
TypeApk,
TypeBitbucket,
TypeComposer,
TypeDebian,
TypeGithub,
TypeGolang,
TypeNPM:
return strings.ToLower(name)
case TypePyPi:
return strings.ToLower(strings.ReplaceAll(name, "_", "-"))
Expand Down
72 changes: 72 additions & 0 deletions testdata/test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,5 +562,77 @@
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "valid alpm purl",
"purl": "pkg:alpm/arch/[email protected]?arch=x86_64",
"canonical_purl": "pkg:alpm/arch/[email protected]?arch=x86_64",
"type": "alpm",
"namespace": "arch",
"name": "pacman",
"version": "6.0.1-1",
"qualifiers": {"arch": "x86_64"},
"subpath": null,
"is_invalid": false
},
{
"description": "alpm namespace and name should be lowercased",
"purl": "pkg:alpm/Arch/[email protected]?arch=x86_64",
"canonical_purl": "pkg:alpm/arch/[email protected]?arch=x86_64",
"type": "alpm",
"namespace": "arch",
"name": "pacman",
"version": "6.0.1-1",
"qualifiers": {"arch": "x86_64"},
"subpath": null,
"is_invalid": false
},
{
"description": "valid apk purl",
"purl": "pkg:apk/alpine/[email protected]?arch=x86_64",
"canonical_purl": "pkg:apk/alpine/[email protected]?arch=x86_64",
"type": "apk",
"namespace": "alpine",
"name": "curl",
"version": "7.83.0-r0",
"qualifiers": {"arch": "x86_64"},
"subpath": null,
"is_invalid": false
},
{
"description": "apk namespace and name should be lowercased",
"purl": "pkg:apk/Alpine/[email protected]?arch=x86_64",
"canonical_purl": "pkg:apk/alpine/[email protected]?arch=x86_64",
"type": "apk",
"namespace": "alpine",
"name": "curl",
"version": "7.83.0-r0",
"qualifiers": {"arch": "x86_64"},
"subpath": null,
"is_invalid": false
},
{
"description": "valid qpkg purl",
"purl": "pkg:qpkg/blackberry/[email protected]",
"canonical_purl": "pkg:qpkg/blackberry/[email protected]",
"type": "qpkg",
"namespace": "blackberry",
"name": "com.qnx.sdp",
"version": "7.0.0.SGA201702151847",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "qpkg namespace should be lowercased",
"purl": "pkg:qpkg/BlackBerry/[email protected]",
"canonical_purl": "pkg:qpkg/blackberry/[email protected]",
"type": "qpkg",
"namespace": "blackberry",
"name": "com.qnx.sdp",
"version": "7.0.0.SGA201702151847",
"qualifiers": null,
"subpath": null,
"is_invalid": false
}
]