Skip to content

Commit

Permalink
Fix huggingface version parsing. The version must be lowercase as spe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Octogonapus committed Jun 15, 2023
1 parent 1f567e3 commit 69d3c91
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ var (
TypeRPM = "rpm"
// TypeSwift is pkg:swift purl
TypeSwift = "swift"
// TypeHuggingface is pkg:huggingface purl.
TypeHuggingface = "huggingface"
)

// Qualifier represents a single key=value qualifier in the package url
Expand Down Expand Up @@ -292,7 +294,7 @@ func FromString(purl string) (PackageURL, error) {
if err != nil {
return PackageURL{}, fmt.Errorf("failed to unescape purl version: %s", err)
}
version = v
version = typeAdjustVersion(purlType, v)

unecapeName, err := url.PathUnescape(name[:atIndex])
if err != nil {
Expand Down Expand Up @@ -360,6 +362,16 @@ func typeAdjustName(purlType, name string) string {
return name
}

// Make any purl type-specific adjustments to the parsed version.
// See https://github.com/package-url/purl-spec#known-purl-types
func typeAdjustVersion(purlType, version string) string {
switch purlType {
case TypeHuggingface:
return strings.ToLower(version)
}
return version
}

// validQualifierKey validates a qualifierKey against our QualifierKeyPattern.
func validQualifierKey(key string) bool {
return QualifierKeyPattern.MatchString(key)
Expand Down

0 comments on commit 69d3c91

Please sign in to comment.