From 810a77143131a076273ce7ce0c48f7168ff44156 Mon Sep 17 00:00:00 2001 From: Paul Malmsten Date: Fri, 28 Oct 2022 13:09:28 -0700 Subject: [PATCH] Prevent lowercasing npm names to support grandfathered packages (#19) npm used to support package names containing capital characters: https://blog.npmjs.org/post/168978377570/new-package-moniker-rules.html Such packages still exist on the npm registry, like this one: https://www.npmjs.com/package/Acid/v/3.0.17 --- src/PackageUrl.cs | 2 +- tests/TestAssets/test-suite-data.json | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/PackageUrl.cs b/src/PackageUrl.cs index c6f6a85..ae49a2e 100644 --- a/src/PackageUrl.cs +++ b/src/PackageUrl.cs @@ -276,7 +276,7 @@ private string ValidateName(string name) } return Type switch { - "nuget" or "cocoapods" or "cpan" or "vsm" or "cran" => name, + "nuget" or "cocoapods" or "cpan" or "vsm" or "cran" or "npm" => name, "pypi" => name.Replace('_', '-').ToLower(), _ => name.ToLower() }; diff --git a/tests/TestAssets/test-suite-data.json b/tests/TestAssets/test-suite-data.json index 5386254..6f97708 100644 --- a/tests/TestAssets/test-suite-data.json +++ b/tests/TestAssets/test-suite-data.json @@ -167,6 +167,18 @@ "subpath": null, "is_invalid": false }, + { + "description": "npm names are case sensitive (npm only requires lowercase names for new packages)", + "purl": "pkg:npm/Acid@3.0.17", + "canonical_purl": "pkg:npm/Acid@3.0.17", + "type": "npm", + "namespace": null, + "name": "Acid", + "version": "3.0.17", + "qualifiers": null, + "subpath": null, + "is_invalid": false + }, { "description": "nuget names are case sensitive", "purl": "pkg:Nuget/EnterpriseLibrary.Common@6.0.1304",