From ea1fe6c6fadb02a2b45ed348271afcb887c75766 Mon Sep 17 00:00:00 2001 From: Xavier Decoster Date: Fri, 12 May 2017 11:26:27 +0200 Subject: [PATCH] Fix Functional Test failure for ODataFeeds.V2FeedExtendedTests.FindPackagesByIdTest #3947 (#3948) --- .../Serializers/V2FeedPackageAnnotationStrategy.cs | 10 ++++++++++ .../V2FeedPackageAnnotationStrategyFacts.cs | 4 ++++ 2 files changed, 14 insertions(+) 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