Skip to content
New issue

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

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

Already on GitHub? # to your account

Add exported field containing all the currently supported types #59

Closed
antgamdia opened this issue Jul 20, 2023 · 0 comments · Fixed by #61
Closed

Add exported field containing all the currently supported types #59

antgamdia opened this issue Jul 20, 2023 · 0 comments · Fixed by #61

Comments

@antgamdia
Copy link
Contributor

As the PURL spec is evolving, other purl-dependant projects might fail to detect whether a given purl type is a valid type or just a random string that looks like a purl.

For instance, if we want to check from "test:ok/name@version", test is a supported type or not, we would have to check if it is one of purl.TypeBitbucket, purl.TypeCocoapods, purl.TypeCargo... etc., as the FromString func does not seem to validate the type,

packageurl-go/packageurl.go

Lines 239 to 243 in 3587d8c

typ, p, ok := strings.Cut(p, "/")
if !ok {
return PackageURL{}, fmt.Errorf("purl is missing type or name")
}
typ = strings.ToLower(typ)

A simplistic approach I can think of is just having an exported SupportedTypes map[string]struct{} like:

var SupportedTypes = map[string]struct{}{
	purl.TypeBitbucket:   {},
	purl.TypeCargo:       {},
	purl.TypeCocoapods:   {},
	purl.TypeComposer:    {},
        ...
}

This way, one could just do sth like: if _, ok := purl.SupportedTypes[myTypeToCheck]; !ok { ... to handle unsupported types.

Do you think it makes sense? If so, I can raise a PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant