Skip to content

Commit 9b85f4c

Browse files
authored
Fixed breadcrumb links for packages with build metadata (#8157)
* 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
1 parent 6975320 commit 9b85f4c

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/NuGetGallery/UrlHelperExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ public static string Package(
228228
string version,
229229
bool relativeUrl = true)
230230
{
231+
string normalized = (version != null) ? NuGetVersionFormatter.Normalize(version) : version;
232+
231233
string result = GetRouteLink(
232234
url,
233235
RouteName.DisplayPackage,
234236
relativeUrl,
235237
routeValues: new RouteValueDictionary
236238
{
237239
{ "id", id },
238-
{ "version", version }
240+
{ "version", normalized }
239241
});
240242

241243
// Ensure trailing slashes for versionless package URLs, as a fix for package filenames that look like known file extensions

tests/NuGetGallery.Facts/Controllers/ApiControllerFacts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,8 +2856,8 @@ public async Task VerifyRecentPopularityStatsDownloads()
28562856

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

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

28632863
[Fact]

tests/NuGetGallery.Facts/UrlHelperExtensionsFacts.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ public void PropagatesNull()
3030
Assert.Null(fixedUrl);
3131
}
3232
}
33+
34+
public class ThePackageBaseHelperMethod
35+
: TestContainer
36+
{
37+
[Fact]
38+
public void UsesNormalizedVersionInUrls()
39+
{
40+
var package = new Package
41+
{
42+
PackageRegistration = new PackageRegistration
43+
{
44+
Id = "TestPackageId"
45+
},
46+
NormalizedVersion = "1.0.0-alpha.1",
47+
Version = "1.0.0-alpha.1+metadata"
48+
};
49+
50+
string fixedUrl = UrlHelperExtensions.Package(TestUtility.MockUrlHelper(), package.Id, package.Version);
51+
52+
Assert.DoesNotContain("metadata", fixedUrl);
53+
Assert.EndsWith(package.NormalizedVersion, fixedUrl);
54+
}
55+
}
3356

3457
public class ThePackageHelperMethod
3558
: TestContainer

0 commit comments

Comments
 (0)