Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

cocoapods, cran, vsm and cpan packages should not be lowered #18

Merged
merged 12 commits into from
Mar 3, 2022
21 changes: 11 additions & 10 deletions src/PackageUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,17 @@ private static string ValidateType(string type)
return type.ToLower();
}

private static string ValidateNamespace(string @namespace)
private string ValidateNamespace(string @namespace)
{
if (@namespace == null)
{
return null;
}
return WebUtility.UrlDecode(@namespace.ToLower());
return Type switch
{
"vsm" or "cran" => WebUtility.UrlDecode(@namespace),
_ => WebUtility.UrlDecode(@namespace.ToLower())
};
}

private string ValidateName(string name)
Expand All @@ -270,15 +274,12 @@ private string ValidateName(string name)
{
throw new MalformedPackageUrlException("The PackageURL name specified is invalid");
gfs marked this conversation as resolved.
Show resolved Hide resolved
}
if (Type == "pypi")
{
name = name.Replace('_', '-');
}
if (Type == "nuget")
return Type switch
{
return name;
}
return name.ToLower();
"nuget" or "cocoapods" or "cpan" or "vsm" or "cran" => name,
"pypi" => name.Replace('_', '-').ToLower(),
_ => name.ToLower()
};
}

private static SortedDictionary<string, string> ValidateQualifiers(string qualifiers)
Expand Down
60 changes: 60 additions & 0 deletions tests/TestAssets/test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,65 @@
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cocoapods names are case sensitive",
"purl": "pkg:cocoapods/[email protected]",
"canonical_purl": "pkg:cocoapods/[email protected]",
"type": "cocoapods",
"namespace": null,
"name": "MapsIndoors",
"version": "3.24.0",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cpan names are case sensitive",
"purl": "pkg:cpan/[email protected]",
"canonical_purl": "pkg:cpan/[email protected]",
"type": "cpan",
"namespace": null,
"name": "Perl-Version",
"version": "1.013",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "cran names are case sensitive",
"purl": "pkg:cran/[email protected]",
"canonical_purl": "pkg:cran/[email protected]",
"type": "cran",
"namespace": null,
"name": "MixTwice",
"version": "2.0",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "Visual Studio Marketplace namespaces are case sensitive",
"purl": "pkg:vsm/MS-CST-E/[email protected]",
"canonical_purl": "pkg:vsm/MS-CST-E/[email protected]",
"type": "vsm",
"namespace": "MS-CST-E",
"name": "vscode-devskim",
"version": "0.6.8",
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "Visual Studio Marketplace names are case sensitive",
"purl": "pkg:vsm/ritwickdey/[email protected]",
"canonical_purl": "pkg:vsm/ritwickdey/[email protected]",
"type": "vsm",
"namespace": "ritwickdey",
"name": "LiveServer",
"version": "5.7.4",
"qualifiers": null,
"subpath": null,
"is_invalid": false
}
]