From 7b27f39553d5804da0d98d633a4b3e749aa3b293 Mon Sep 17 00:00:00 2001 From: "Brandyn Bayes (Microsoft)" Date: Wed, 1 Feb 2023 10:43:56 -0800 Subject: [PATCH] Standardize namespace and name normalization to match Python library (#22) * Standardize namespace and name normalization to match Python library * Add github example to test data --- src/PackageUrl.cs | 8 ++++---- tests/TestAssets/test-suite-data.json | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/PackageUrl.cs b/src/PackageUrl.cs index ae49a2e..2a7a0e8 100644 --- a/src/PackageUrl.cs +++ b/src/PackageUrl.cs @@ -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) }; } @@ -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 }; } diff --git a/tests/TestAssets/test-suite-data.json b/tests/TestAssets/test-suite-data.json index 6f97708..4793dab 100644 --- a/tests/TestAssets/test-suite-data.json +++ b/tests/TestAssets/test-suite-data.json @@ -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 } ]