Use OSPath.PathComparer in StaticWebAssetEndpoint.ToAssetFileDictionary#54749
Draft
jankratochvilcz wants to merge 2 commits into
Draft
Use OSPath.PathComparer in StaticWebAssetEndpoint.ToAssetFileDictionary#54749jankratochvilcz wants to merge 2 commits into
jankratochvilcz wants to merge 2 commits into
Conversation
…sitively on Windows StaticWebAssetEndpoint.ToAssetFileDictionary builds its keying dictionary with the default ordinal comparer (StaticWebAssetEndpoint.cs:178). On Windows the filesystem is case-insensitive, but two endpoints whose AssetFile values differ only in casing (e.g. 'C:\Repo\WWWRoot\site.css' vs 'c:\repo\wwwroot\site.css') currently land in separate buckets. This makes downstream lookups such as ApplyCompressionNegotiation's endpointsByAsset.TryGetValue(compressedAsset.Identity, ...) silently miss when MSBuild round-trips path casing differently between producers (ResolveProjectReferences vs DefineStaticWebAssets, etc.), dropping the related-asset's endpoint from compression-negotiation processing. Sibling SWA dictionaries (GeneratePackageAssetsManifestFile.cs:92, UpdatePackageStaticWebAssets.cs:46) pass Utils.OSPath.PathComparer for exactly this reason. The 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. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes the previously failing GroupsEndpoints_ByPath_CaseInsensitively_OnWindows test by passing Utils.OSPath.PathComparer (OrdinalIgnoreCase on Windows, Ordinal on Linux/macOS) to the keying dictionary so AssetFile path lookups match the OS filesystem semantics, consistent with sibling SWA dictionaries (GeneratePackageAssetsManifestFile.cs:92, UpdatePackageStaticWebAssets.cs:46). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Thanks for your PR, @jankratochvilcz. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a latent path-comparer bug in
StaticWebAssetEndpoint.ToAssetFileDictionary(src/StaticWebAssetsSdk/Tasks/Data/StaticWebAssetEndpoint.cs:178). The dictionary keys are absolute filesystem paths (endpoint.AssetFile, typically populated via MSBuild's%(FullPath)modifier), but the dictionary was constructed without a comparer — defaulting to ordinal case-sensitive on all platforms.Impact
On Windows the filesystem is case-insensitive, so two endpoints whose
AssetFilevalues differ only in casing (e.g.C:\Repo\WWWRoot\site.cssvsc:\repo\wwwroot\site.css) land in separate buckets. This makes downstream lookups such asApplyCompressionNegotiation'sendpointsByAsset.TryGetValue(compressedAsset.Identity, …)silently miss when MSBuild round-trips path casing differently between producers (e.g.ResolveProjectReferencesvsDefineStaticWebAssets), dropping the related-asset's endpoint from compression-negotiation processing.Sibling SWA dictionaries pass
Utils.OSPath.PathComparerfor exactly this reason — seeGeneratePackageAssetsManifestFile.cs:92andUpdatePackageStaticWebAssets.cs:46.Changes (TDD)
Add failing test— addsStaticWebAssetEndpointToAssetFileDictionaryTest.GroupsEndpoints_ByPath_CaseInsensitively_OnWindows, a Windows-onlyPlatformSpecificFactthat asserts case-divergentAssetFilevalues share a single dictionary entry. Fails onmain(default ordinal comparer).Fix— passOSPath.PathComparer(OrdinalIgnoreCaseon Windows,Ordinalon Linux/macOS) to theDictionary<string, List<StaticWebAssetEndpoint>>constructor.The test is Windows-only because
OSPath.PathComparerisOrdinalIgnoreCaseonly on Windows; on Linux/macOS it isStringComparer.Ordinal(matching the case-sensitive filesystem), which is observationally identical to the defaultDictionarycomparer.Found during MT-safety audit of #54703.