Skip to content

Commit

Permalink
Fixed breadcrumb links for packages with build metadata (#8157)
Browse files Browse the repository at this point in the history
* Fixed breadcrumb links for packages with build metadata #8136

* added null reference check

* added unit test

* removed extraneous newlines

* fixed test as links now have normalised version numbers on the end

Address #8136
  • Loading branch information
rocklan authored Aug 18, 2020
1 parent 6975320 commit 9b85f4c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/NuGetGallery/UrlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ public static string Package(
string version,
bool relativeUrl = true)
{
string normalized = (version != null) ? NuGetVersionFormatter.Normalize(version) : version;

string result = GetRouteLink(
url,
RouteName.DisplayPackage,
relativeUrl,
routeValues: new RouteValueDictionary
{
{ "id", id },
{ "version", version }
{ "version", normalized }
});

// Ensure trailing slashes for versionless package URLs, as a fix for package filenames that look like known file extensions
Expand Down
4 changes: 2 additions & 2 deletions tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2856,8 +2856,8 @@ public async Task VerifyRecentPopularityStatsDownloads()

JArray result = JArray.Parse(contentResult.Content);

Assert.True((string)result[3]["Gallery"] == "/packages/B/1.1", "unexpected content result[3].Gallery");
Assert.True((int)result[2]["Downloads"] == 5, "unexpected content result[2].Downloads");
Assert.Equal("/packages/B/1.1.0", (string)result[3]["Gallery"]);
Assert.Equal(5, (int)result[2]["Downloads"]);
}

[Fact]
Expand Down
23 changes: 23 additions & 0 deletions tests/NuGetGallery.Facts/UrlHelperExtensionsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ public void PropagatesNull()
Assert.Null(fixedUrl);
}
}

public class ThePackageBaseHelperMethod
: TestContainer
{
[Fact]
public void UsesNormalizedVersionInUrls()
{
var package = new Package
{
PackageRegistration = new PackageRegistration
{
Id = "TestPackageId"
},
NormalizedVersion = "1.0.0-alpha.1",
Version = "1.0.0-alpha.1+metadata"
};

string fixedUrl = UrlHelperExtensions.Package(TestUtility.MockUrlHelper(), package.Id, package.Version);

Assert.DoesNotContain("metadata", fixedUrl);
Assert.EndsWith(package.NormalizedVersion, fixedUrl);
}
}

public class ThePackageHelperMethod
: TestContainer
Expand Down

0 comments on commit 9b85f4c

Please sign in to comment.