Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils;
using Microsoft.Build.Framework;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;
Expand Down Expand Up @@ -175,7 +176,7 @@ internal void MarkProperiesAsModified()

internal static IDictionary<string, List<StaticWebAssetEndpoint>> ToAssetFileDictionary(ITaskItem[] candidateEndpoints)
{
var result = new Dictionary<string, List<StaticWebAssetEndpoint>>(candidateEndpoints.Length / 2);
var result = new Dictionary<string, List<StaticWebAssetEndpoint>>(candidateEndpoints.Length / 2, OSPath.PathComparer);

foreach (var candidate in candidateEndpoints)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.NET.TestFramework;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;

public class StaticWebAssetEndpointToAssetFileDictionaryTest
{
// ToAssetFileDictionary keys are absolute filesystem paths (endpoint.AssetFile, typically
// populated by upstream targets via MSBuild's %(FullPath) modifier). On Windows the
// filesystem is case-insensitive, so two endpoints whose AssetFile values differ only in
// casing must collide into a single dictionary entry — otherwise downstream lookups such
// as ApplyCompressionNegotiation's `endpointsByAsset.TryGetValue(compressedAsset.Identity, ...)`
// can silently miss when MSBuild round-trips path casing differently between producers
// (e.g. ResolveProjectReferences vs DefineStaticWebAssets).
//
// This test is Windows-only because OSPath.PathComparer is OrdinalIgnoreCase only on
// Windows; on Linux/macOS it is StringComparer.Ordinal (matching the case-sensitive
// filesystem), which is observationally identical to the default Dictionary comparer.
[PlatformSpecificFact(TestPlatforms.Windows)]
public void GroupsEndpoints_ByPath_CaseInsensitively_OnWindows()
{
var upperCased = MakeEndpointItem("C:\\Repo\\WWWRoot\\site.css", "/_content/lib/site.css");
var lowerCased = MakeEndpointItem("c:\\repo\\wwwroot\\site.css", "/_content/lib/site.css.gz");

var result = StaticWebAssetEndpoint.ToAssetFileDictionary([upperCased, lowerCased]);

result.Should().HaveCount(1,
"two endpoints whose AssetFile values differ only in casing point to the same " +
"file on Windows and must share a single dictionary entry");
var only = result.Values.Single();
only.Should().HaveCount(2,
"both endpoints must be grouped under the case-insensitive key");
}

private static ITaskItem MakeEndpointItem(string assetFile, string route) =>
new TaskItem(route, new Dictionary<string, string>
{
[nameof(StaticWebAssetEndpoint.AssetFile)] = assetFile,
[nameof(StaticWebAssetEndpoint.Selectors)] = "",
[nameof(StaticWebAssetEndpoint.ResponseHeaders)] = "",
[nameof(StaticWebAssetEndpoint.EndpointProperties)] = "",
});
}
Loading