Skip to content

Commit 276c658

Browse files
author
Daniel Jacinto
authored
[TFM Display][Bug] Packages with backslash path didn't show TFM information. (#8995)
* Normalization of package entry path. * test fix. * Use ToList() to avoid more allocations. * Update signature to be IList instead of IEnumerable.
1 parent 6c475d9 commit 276c658

8 files changed

Lines changed: 44 additions & 16 deletions

File tree

src/NuGetGallery/Helpers/ValidationHelper.cs renamed to src/NuGetGallery.Services/Helpers/PackageValidationHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
67
using NuGet.Packaging;
78

89
namespace NuGetGallery.Helpers
910
{
10-
public class ValidationHelper
11+
public class PackageValidationHelper
1112
{
1213
public static bool HasDuplicatedEntries(PackageArchiveReader nuGetPackage)
1314
{
1415
// Normalize paths and ensures case sensitivity is also considered
15-
var packageFiles = nuGetPackage.GetFiles().Select(packageFile => FileNameHelper.GetZipEntryPath(packageFile));
16+
var packageFiles = GetNormalizedEntryPaths(nuGetPackage);
1617

1718
return packageFiles.Count() != packageFiles.Distinct(StringComparer.OrdinalIgnoreCase).Count();
1819
}
20+
21+
public static IList<string> GetNormalizedEntryPaths(PackageArchiveReader nuGetPackage)
22+
{
23+
return nuGetPackage.GetFiles().Select(packageFile => FileNameHelper.GetZipEntryPath(packageFile)).ToList();
24+
}
1925
}
2026
}

src/NuGetGallery.Services/NuGetGallery.Services.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<Compile Include="Helpers\LatestPackageRouteVerifier.cs" />
154154
<Compile Include="Helpers\MailAddressConverter.cs" />
155155
<Compile Include="Helpers\UploadHelper.cs" />
156+
<Compile Include="Helpers\PackageValidationHelper.cs" />
156157
<Compile Include="Mail\GalleryEmailRecipientsUtility.cs" />
157158
<Compile Include="Mail\Messages\PackageOwnerAddedMessage.cs" />
158159
<Compile Include="Mail\Messages\PackageOwnerRemovedMessage.cs" />

src/NuGetGallery.Services/PackageManagement/PackageService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using NuGet.Services.Entities;
1818
using NuGet.Versioning;
1919
using NuGetGallery.Auditing;
20+
using NuGetGallery.Helpers;
2021
using NuGetGallery.Packaging;
2122
using NuGetGallery.Security;
2223
using PackageType = NuGet.Packaging.Core.PackageType;
@@ -711,7 +712,7 @@ public virtual IEnumerable<NuGetFramework> GetSupportedFrameworks(PackageArchive
711712
{
712713
if (_featureFlagService.ArePatternSetTfmHeuristicsEnabled())
713714
{
714-
return GetSupportedFrameworks(package.NuspecReader, package.GetFiles().ToList());
715+
return GetSupportedFrameworks(package.NuspecReader, PackageValidationHelper.GetNormalizedEntryPaths(package));
715716
}
716717

717718
return package.GetSupportedFrameworks();

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
<Compile Include="Extensions\ImageExtensions.cs" />
222222
<Compile Include="Filters\AdminActionAttribute.cs" />
223223
<Compile Include="Helpers\AdminHelper.cs" />
224-
<Compile Include="Helpers\ValidationHelper.cs" />
225224
<Compile Include="Helpers\ViewModelExtensions\DeleteAccountListPackageItemViewModelFactory.cs" />
226225
<Compile Include="Helpers\ViewModelExtensions\DeletePackageViewModelFactory.cs" />
227226
<Compile Include="Helpers\ViewModelExtensions\DisplayLicenseViewModelFactory.cs" />

src/NuGetGallery/Services/PackageMetadataValidationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ private async Task<PackageValidationResult> CheckPackageEntryCountAsync(
683683

684684
private PackageValidationResult CheckPackageDuplicatedEntries(PackageArchiveReader nuGetPackage)
685685
{
686-
if (ValidationHelper.HasDuplicatedEntries(nuGetPackage))
686+
if (PackageValidationHelper.HasDuplicatedEntries(nuGetPackage))
687687
{
688688
return PackageValidationResult.Invalid(Strings.UploadPackage_PackageContainsDuplicatedEntries);
689689
}

src/NuGetGallery/Services/SymbolPackageUploadService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task<SymbolPackageValidationResult> ValidateUploadedSymbolsPackage(
9090
}
9191

9292
// Check for duplicated entries in symbols package
93-
if (ValidationHelper.HasDuplicatedEntries(packageToPush))
93+
if (PackageValidationHelper.HasDuplicatedEntries(packageToPush))
9494
{
9595
return SymbolPackageValidationResult.Invalid(Strings.UploadPackage_PackageContainsDuplicatedEntries);
9696
}

tests/NuGetGallery.Facts/Helpers/ValidationHelperFacts.cs renamed to tests/NuGetGallery.Facts/Helpers/PackageValidationHelperFacts.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
5+
using System.Linq;
56
using Moq;
67
using NuGetGallery.TestUtils;
78
using Xunit;
89

910
namespace NuGetGallery.Helpers
1011
{
11-
public class ValidationHelperFacts
12+
public class PackageValidationHelperFacts
1213
{
1314
public class HasDuplicatedEntriesMethod
1415
{
@@ -25,10 +26,10 @@ public class HasDuplicatedEntriesMethod
2526
public void WithDuplicatedEntries_ReturnsFalse(params string[] entryNames)
2627
{
2728
// Arrange
28-
var package = GeneratePackage(entryNames: entryNames);
29+
var package = PackageValidationHelperFacts.GeneratePackage(entryNames: entryNames);
2930

3031
// Act
31-
var hasDuplicatedEntries = ValidationHelper.HasDuplicatedEntries(package.Object);
32+
var hasDuplicatedEntries = PackageValidationHelper.HasDuplicatedEntries(package.Object);
3233

3334
// Assert
3435
Assert.True(hasDuplicatedEntries);
@@ -42,20 +43,40 @@ public void WithDuplicatedEntries_ReturnsFalse(params string[] entryNames)
4243
public void WithNoDuplicatedEntries_ReturnsTrue(params string[] entryNames)
4344
{
4445
// Arrange
45-
var package = GeneratePackage(entryNames: entryNames);
46+
var package = PackageValidationHelperFacts.GeneratePackage(entryNames: entryNames);
4647

4748
// Act
48-
var hasDuplicatedEntries = ValidationHelper.HasDuplicatedEntries(package.Object);
49+
var hasDuplicatedEntries = PackageValidationHelper.HasDuplicatedEntries(package.Object);
4950

5051
// Assert
5152
Assert.False(hasDuplicatedEntries);
5253
}
54+
}
5355

54-
private Mock<TestPackageReader> GeneratePackage(IReadOnlyList<string> entryNames)
56+
public class GetNormalizedEntryPathsMethod
57+
{
58+
[Theory]
59+
[InlineData("./net50\\file.dll", "net50/file.dll")]
60+
[InlineData("\\netstandard10\\file.dll", "netstandard10/file.dll")]
61+
[InlineData("\\\\net472", "net472")]
62+
public void AlwaysReturnsCorrectPath(string path, string correctPath)
5563
{
56-
var packageStream = PackageServiceUtility.CreateNuGetPackageStream(entryNames: entryNames);
57-
return PackageServiceUtility.CreateNuGetPackage(packageStream);
64+
// Arrange
65+
var paths = new string[] { path };
66+
var package = PackageValidationHelperFacts.GeneratePackage(entryNames: paths);
67+
68+
// Act
69+
var normalizedPaths = PackageValidationHelper.GetNormalizedEntryPaths(package.Object);
70+
71+
// Assert
72+
Assert.Equal(normalizedPaths.ElementAt(1), correctPath);
5873
}
5974
}
75+
76+
public static Mock<TestPackageReader> GeneratePackage(IReadOnlyList<string> entryNames)
77+
{
78+
var packageStream = PackageServiceUtility.CreateNuGetPackageStream(entryNames: entryNames);
79+
return PackageServiceUtility.CreateNuGetPackage(packageStream);
80+
}
6081
}
61-
}
82+
}

tests/NuGetGallery.Facts/NuGetGallery.Facts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<Compile Include="Authentication\Providers\CommonAuth\AzureActiveDirectoryV2AuthenticatorFacts.cs" />
8484
<Compile Include="Authentication\TestCredentialHelper.cs" />
8585
<Compile Include="Extensions\CakeBuildManagerExtensionsFacts.cs" />
86-
<Compile Include="Helpers\ValidationHelperFacts.cs" />
86+
<Compile Include="Helpers\PackageValidationHelperFacts.cs" />
8787
<Compile Include="Infrastructure\ODataCacheOutputAttributeFacts.cs" />
8888
<Compile Include="Queries\AutocompleteDatabasePackageIdsQueryFacts.cs" />
8989
<Compile Include="Queries\AutocompleteDatabasePackageVersionsQueryFacts.cs" />

0 commit comments

Comments
 (0)