diff --git a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs index 8ddf9562e0..64f7128f47 100644 --- a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs +++ b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs @@ -87,10 +87,20 @@ private static Uri BuildIdLink(string id, string version, HttpRequestMessage req var packageIdentityQuery = $"(Id='{id}',Version='{version}')"; var localPath = request.RequestUri.LocalPath // Remove closing brackets from Packages collection + .Replace("/GetUpdates", "/Packages") + .Replace("/FindPackagesById", "/Packages") + .Replace("/Search", "/Packages") .Replace("/Packages()", "/Packages") // Remove package identity query .Replace(packageIdentityQuery, string.Empty); + // Ensure any OData queries remaining are stripped off + var queryStartIndex = localPath.IndexOf('('); + if (queryStartIndex != -1) + { + localPath = localPath.Substring(0, queryStartIndex); + } + 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 2084b10636..ba58f4517d 100644 --- a/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs +++ b/tests/NuGetGallery.Facts/OData/Serializers/V2FeedPackageAnnotationStrategyFacts.cs @@ -85,6 +85,10 @@ public void SetsAtomEntryMetadataAnnotation() [InlineData("https://localhost/api/v2/Packages")] [InlineData("https://localhost/api/v2/Packages()")] [InlineData("https://localhost/api/v2/Packages(Id='SomePackageId',Version='1.0.0')")] + [InlineData("https://localhost/api/v2/FindPackagesById()?id='SomePackageId'")] + [InlineData("https://localhost/api/v2/FindPackagesById(Id='SomePackageId')")] + [InlineData("https://localhost/api/v2/Search()?searchTerm='SomePackageId'")] + [InlineData("https://localhost/api/v2/GetUpdates()?packageIds=='SomePackageId'")] public void NormalizesNavigationLinksWhenSet(string requestUri) { // Arrange