Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
In feed2catalog, default to empty string if the version range is miss…
Browse files Browse the repository at this point in the history
…ing or invalid (#253)

Fix NuGet/NuGetGallery#3482
  • Loading branch information
joelverhagen committed Oct 25, 2017
1 parent 37a8043 commit 42558fa
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Catalog/Helpers/NuGetVersionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static string NormalizeVersion(string version)

return parsedVersion.ToNormalizedString();
}

public static string NormalizeVersionRange(string versionRange)
public static string NormalizeVersionRange(string versionRange, string defaultValue)
{
VersionRange parsedVersionRange;
if (!VersionRange.TryParse(versionRange, out parsedVersionRange))
{
return versionRange;
return defaultValue;
}

return parsedVersionRange.ToNormalizedString();
Expand Down
9 changes: 8 additions & 1 deletion src/Catalog/Helpers/XsltHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace NuGet.Services.Metadata.Catalog
{
public class XsltHelper
{
/// <summary>
/// Default to an empty string if the dependency version range is invalid or missing. This is meant to be a
/// predictable signal to the client that they need to handle this invalid version case. The official NuGet
/// client treats this as a dependency of any version.
/// </summary>
private static readonly string DefaultVersionRange = string.Empty;

public XPathNavigator Split(string original)
{
char[] trimChar = { ',', ' ', '\t', '|', ';' };
Expand Down Expand Up @@ -52,7 +59,7 @@ public string GetFullVersionString(string original)

public string NormalizeVersionRange(string original)
{
return NuGetVersionUtility.NormalizeVersionRange(original);
return NuGetVersionUtility.NormalizeVersionRange(original, DefaultVersionRange);
}

public string IsPrerelease(string original)
Expand Down
24 changes: 24 additions & 0 deletions tests/CatalogTests/CatalogTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@
<None Include="TestData\EmptyDependencyIdWithGroups.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\EmptyDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\EmptyDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\InvalidDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\InvalidDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\MissingDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\MissingDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\Newtonsoft.Json.9.0.2-beta1.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -224,6 +242,12 @@
<None Include="TestData\WhitespaceDependencyId.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\WhitespaceDependencyVersionRange.0.1.0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\WhitespaceDependencyVersionRange.0.1.0.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
21 changes: 19 additions & 2 deletions tests/CatalogTests/Helpers/NuGetVersionUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,30 @@ public void NormalizeVersion(string input, string expected)
[InlineData("invalid", "invalid")]
public void NormalizeVersionRange(string input, string expected)
{
// Arrange & Act
var actual = NuGetVersionUtility.NormalizeVersionRange(input);
// Arrange
var defaultValue = input;

// Arrange
var actual = NuGetVersionUtility.NormalizeVersionRange(input, defaultValue);

// Assert
Assert.Equal(expected, actual);
}

[Fact]
public void NormalizeVersionRange_UsesDifferentDefault()
{
// Arrange
var input = "invalid";
var defaultValue = "(, )";

// Act
var actual = NuGetVersionUtility.NormalizeVersionRange(input, defaultValue);

// Assert
Assert.Equal(defaultValue, actual);
}

[Theory]
[InlineData("1.0.0-alpha.1", "1.0.0-alpha.1")]
[InlineData("1.0.0-alpha+githash", "1.0.0-alpha+githash")]
Expand Down
4 changes: 4 additions & 0 deletions tests/CatalogTests/PackageCatalogItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class PackageCatalogItemTests
[InlineData("OneValidDependencyOneEmptyId.0.1.0")] // One valid dependency and one with empty string ID
[InlineData("OneValidDependencyOneEmptyIdWithGroups.0.1.0")] // Using dependency groups, one valid dependency and one with empty string ID
[InlineData("WhitespaceDependencyId.0.1.0")] // One dependency with an ID only containing whitespace
[InlineData("EmptyDependencyVersionRange.0.1.0")] // A dependency with a version range that is an empty string
[InlineData("InvalidDependencyVersionRange.0.1.0")] //A dependency with a version range that is invalid
[InlineData("MissingDependencyVersionRange.0.1.0")] // A dependency with no version range attribute
[InlineData("WhitespaceDependencyVersionRange.0.1.0")] // A dependency with a version range that is whitespace
public void CreateContent_ProducesExpectedJson(string packageName)
{
// Arrange
Expand Down
84 changes: 84 additions & 0 deletions tests/CatalogTests/TestData/EmptyDependencyVersionRange.0.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json",
"@type": [
"PackageDetails",
"catalog:Permalink"
],
"authors": "EmptyDependencyVersionRange",
"catalog:commitId": "4aee0ef4-a039-4460-bd5f-98f944e33289",
"catalog:commitTimeStamp": "2017-01-04T08:15:00Z",
"created": "2017-01-01T08:15:00Z",
"description": "EmptyDependencyVersionRange",
"id": "EmptyDependencyVersionRange",
"isPrerelease": false,
"lastEdited": "2017-01-02T08:15:00Z",
"listed": true,
"packageHash": "J1NrM0aeDXk3kdjY3Aby8duP+mAt1JN/srVW5AMDIFXJXhWjZgmwAnAKBBrO6VDWXg2hi1x+uaWLHI0dUXraUg==",
"packageHashAlgorithm": "SHA512",
"packageSize": 450,
"published": "2017-01-03T08:15:00Z",
"title": "EmptyDependencyVersionRange",
"verbatimVersion": "0.1.0",
"version": "0.1.0",
"dependencyGroups": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#dependencygroup",
"@type": "PackageDependencyGroup",
"dependencies": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#dependencygroup/nuget.versioning",
"@type": "PackageDependency",
"id": "NuGet.Versioning",
"range": ""
}
]
}
],
"packageEntries": [
{
"@id": "http://example/data/2017.01.04.08.15.00/emptydependencyversionrange.0.1.0.json#EmptyDependencyVersionRange.nuspec",
"@type": "PackageEntry",
"compressedLength": 248,
"fullName": "EmptyDependencyVersionRange.nuspec",
"length": 504,
"name": "EmptyDependencyVersionRange.nuspec"
}
],
"@context": {
"@vocab": "http://schema.nuget.org/schema#",
"catalog": "http://schema.nuget.org/catalog#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dependencies": {
"@id": "dependency",
"@container": "@set"
},
"dependencyGroups": {
"@id": "dependencyGroup",
"@container": "@set"
},
"packageEntries": {
"@id": "packageEntry",
"@container": "@set"
},
"supportedFrameworks": {
"@id": "supportedFramework",
"@container": "@set"
},
"tags": {
"@id": "tag",
"@container": "@set"
},
"published": {
"@type": "xsd:dateTime"
},
"created": {
"@type": "xsd:dateTime"
},
"lastEdited": {
"@type": "xsd:dateTime"
},
"catalog:commitTimeStamp": {
"@type": "xsd:dateTime"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json",
"@type": [
"PackageDetails",
"catalog:Permalink"
],
"authors": "InvalidDependencyVersionRange",
"catalog:commitId": "4aee0ef4-a039-4460-bd5f-98f944e33289",
"catalog:commitTimeStamp": "2017-01-04T08:15:00Z",
"created": "2017-01-01T08:15:00Z",
"description": "InvalidDependencyVersionRange",
"id": "InvalidDependencyVersionRange",
"isPrerelease": false,
"lastEdited": "2017-01-02T08:15:00Z",
"listed": true,
"packageHash": "RFCB7aV+m/vj0CYW3SmnLUd8jMYYJpOw+fz7hDNERlwUjz2rU+6lCVA2bdIko3YYc68jJN3n07S2OgKrUDwPBg==",
"packageHashAlgorithm": "SHA512",
"packageSize": 473,
"published": "2017-01-03T08:15:00Z",
"title": "InvalidDependencyVersionRange",
"verbatimVersion": "0.1.0",
"version": "0.1.0",
"dependencyGroups": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#dependencygroup",
"@type": "PackageDependencyGroup",
"dependencies": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#dependencygroup/nuget.versioning",
"@type": "PackageDependency",
"id": "NuGet.Versioning",
"range": ""
}
]
}
],
"packageEntries": [
{
"@id": "http://example/data/2017.01.04.08.15.00/invaliddependencyversionrange.0.1.0.json#InvalidDependencyVersionRange.nuspec",
"@type": "PackageEntry",
"compressedLength": 267,
"fullName": "InvalidDependencyVersionRange.nuspec",
"length": 530,
"name": "InvalidDependencyVersionRange.nuspec"
}
],
"@context": {
"@vocab": "http://schema.nuget.org/schema#",
"catalog": "http://schema.nuget.org/catalog#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dependencies": {
"@id": "dependency",
"@container": "@set"
},
"dependencyGroups": {
"@id": "dependencyGroup",
"@container": "@set"
},
"packageEntries": {
"@id": "packageEntry",
"@container": "@set"
},
"supportedFrameworks": {
"@id": "supportedFramework",
"@container": "@set"
},
"tags": {
"@id": "tag",
"@container": "@set"
},
"published": {
"@type": "xsd:dateTime"
},
"created": {
"@type": "xsd:dateTime"
},
"lastEdited": {
"@type": "xsd:dateTime"
},
"catalog:commitTimeStamp": {
"@type": "xsd:dateTime"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"@id": "http://example/data/2017.01.04.08.15.00/missingdependencyversionrange.0.1.0.json",
"@type": [
"PackageDetails",
"catalog:Permalink"
],
"authors": "MissingDependencyVersionRange",
"catalog:commitId": "4aee0ef4-a039-4460-bd5f-98f944e33289",
"catalog:commitTimeStamp": "2017-01-04T08:15:00Z",
"created": "2017-01-01T08:15:00Z",
"description": "MissingDependencyVersionRange",
"id": "MissingDependencyVersionRange",
"isPrerelease": false,
"lastEdited": "2017-01-02T08:15:00Z",
"listed": true,
"packageHash": "7K0E8VKZX8of+E4LU2gpnQbjA74nubVDhVDPLOdiRuYyMecuOu3eZ33QmVJ+ZsqLpZB/jnVEUUmUvL7sA4Y+JA==",
"packageHashAlgorithm": "SHA512",
"packageSize": 450,
"published": "2017-01-03T08:15:00Z",
"title": "MissingDependencyVersionRange",
"verbatimVersion": "0.1.0",
"version": "0.1.0",
"dependencyGroups": [
{
"@id": "http://example/data/2017.01.04.08.15.00/missingdependencyversionrange.0.1.0.json#dependencygroup",
"@type": "PackageDependencyGroup",
"dependencies": [
{
"@id": "http://example/data/2017.01.04.08.15.00/missingdependencyversionrange.0.1.0.json#dependencygroup/nuget.versioning",
"@type": "PackageDependency",
"id": "NuGet.Versioning",
"range": ""
}
]
}
],
"packageEntries": [
{
"@id": "http://example/data/2017.01.04.08.15.00/missingdependencyversionrange.0.1.0.json#MissingDependencyVersionRange.nuspec",
"@type": "PackageEntry",
"compressedLength": 244,
"fullName": "MissingDependencyVersionRange.nuspec",
"length": 501,
"name": "MissingDependencyVersionRange.nuspec"
}
],
"@context": {
"@vocab": "http://schema.nuget.org/schema#",
"catalog": "http://schema.nuget.org/catalog#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dependencies": {
"@id": "dependency",
"@container": "@set"
},
"dependencyGroups": {
"@id": "dependencyGroup",
"@container": "@set"
},
"packageEntries": {
"@id": "packageEntry",
"@container": "@set"
},
"supportedFrameworks": {
"@id": "supportedFramework",
"@container": "@set"
},
"tags": {
"@id": "tag",
"@container": "@set"
},
"published": {
"@type": "xsd:dateTime"
},
"created": {
"@type": "xsd:dateTime"
},
"lastEdited": {
"@type": "xsd:dateTime"
},
"catalog:commitTimeStamp": {
"@type": "xsd:dateTime"
}
}
}
Binary file not shown.
Loading

0 comments on commit 42558fa

Please sign in to comment.