Fix StaticWebAssets base path prefix detection using path segment comparison #52277
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.
Summary
When computing endpoints for reference static web assets, the base path prefix check was using
string.StartsWithwhich incorrectly matched routes likeApp1.styles.cssagainst base pathApp1. This caused the base path to not be prepended, resulting in missing routes.Problem
The bug occurs in
ComputeEndpointsForReferenceStaticWebAssetswhen determining if a route already has the base path applied. The original check:Would incorrectly match:
App1.styles.csswith base pathApp1→ incorrectly skipped (starts with "App1")App1.lib.module.jswith base pathApp1→ incorrectly skippedThis resulted in these files being served without the proper base path prefix in multi-project Blazor scenarios.
Solution
Introduced
StaticWebAssetEndpoint.RouteHasPathPrefixmethod that usesPathTokenizerto compare paths segment-by-segment, ensuring only proper path segment boundaries are matched:App1/css/app.cssApp1App1.styles.cssApp1App1Bundle/app.jsApp1App1App1The comparison is case-insensitive and handles both
/and\path separators.Testing
RouteHasPathPrefixcovering positive and negative matchesComputeEndpointsForReferenceStaticWebAssetsTestFiles Changed
ComputeEndpointsForReferenceStaticWebAssets.cs- Use new segment-based prefix checkStaticWebAssetEndpoint.cs- AddRouteHasPathPrefixhelper methodStaticWebAssetEndpointTest.cs- Unit tests forRouteHasPathPrefixComputeEndpointsForReferenceStaticWebAssetsTest.cs- Regression tests