Skip to content

Commit

Permalink
Standardize namespace and name normalization to match Python library (#…
Browse files Browse the repository at this point in the history
…22)

* Standardize namespace and name normalization to match Python library

* Add github example to test data
  • Loading branch information
brbayes-msft committed Feb 1, 2023
1 parent 810a771 commit 7b27f39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/PackageUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ private string ValidateNamespace(string @namespace)
}
return Type switch
{
"vsm" or "cran" => WebUtility.UrlDecode(@namespace),
_ => WebUtility.UrlDecode(@namespace.ToLower())
"bitbucket" or "github" or "pypi" or "gitlab" => WebUtility.UrlDecode(@namespace.ToLower()),
_ => WebUtility.UrlDecode(@namespace)
};
}

Expand All @@ -276,9 +276,9 @@ private string ValidateName(string name)
}
return Type switch
{
"nuget" or "cocoapods" or "cpan" or "vsm" or "cran" or "npm" => name,
"bitbucket" or "github" or "gitlab" => name.ToLower(),
"pypi" => name.Replace('_', '-').ToLower(),
_ => name.ToLower()
_ => name
};
}

Expand Down
24 changes: 24 additions & 0 deletions tests/TestAssets/test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,29 @@
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "Maven names are case sensitive",
"purl": "pkg:maven/com.googlecode.javaewah/JavaEWAH@1.1.12",
"canonical_purl": "pkg:maven/com.googlecode.javaewah/JavaEWAH@1.1.12",
"type": "maven",
"namespace": "com.googlecode.javaewah",
"name": "JavaEWAH",
"version": "1.1.12",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "github namespace and name should be lowercased",
"purl": "pkg:github/Package-url/purl-Spec@244fd47e07d1004f0aed9c",
"canonical_purl": "pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c",
"type": "github",
"namespace": "package-url",
"name": "purl-spec",
"version": "244fd47e07d1004f0aed9c",
"qualifiers": null,
"subpath": null,
"is_invalid": false
}
]

0 comments on commit 7b27f39

Please sign in to comment.