diff --git a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs index 60b5cae411..8ddf9562e0 100644 --- a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs +++ b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs @@ -85,7 +85,11 @@ private static void NormalizeNavigationLinks(ODataEntry entry, HttpRequestMessag private static Uri BuildIdLink(string id, string version, HttpRequestMessage request) { var packageIdentityQuery = $"(Id='{id}',Version='{version}')"; - var localPath = request.RequestUri.LocalPath.Replace(packageIdentityQuery, string.Empty); + var localPath = request.RequestUri.LocalPath + // Remove closing brackets from Packages collection + .Replace("/Packages()", "/Packages") + // Remove package identity query + .Replace(packageIdentityQuery, string.Empty); return new Uri($"{request.RequestUri.Scheme}://{request.RequestUri.Host}{localPath}{packageIdentityQuery}"); } diff --git a/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs b/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs index 843eade501..2084b10636 100644 --- a/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs +++ b/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs @@ -83,6 +83,7 @@ public void SetsAtomEntryMetadataAnnotation() [Theory] [InlineData("https://localhost/api/v2/Packages")] + [InlineData("https://localhost/api/v2/Packages()")] [InlineData("https://localhost/api/v2/Packages(Id='SomePackageId',Version='1.0.0')")] public void NormalizesNavigationLinksWhenSet(string requestUri) {