Skip to content

Conversation

@DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented May 16, 2025

Backport of #11864 to release/dev17.14

Customer Impact

Regression

Testing

  • Manual testing of scenario with known repro project. The issue is present without the fix and resolved with the fix.
  • Tested mainline scenarios, such as OrchardCore and MudBlazor. These continue working with the fix.

Risk

Medium. This affects how every Razor file is compiled in Visual Studio at design-time. However, this risk is mitigated by testing large solutions such as OrchardCore and MudBlazor.

Add ReadOnlySpan<T>.StartsWith(...) and EndWith methods that take a single T value. These were added for convenience in .NET 9.

Note that these are polyfills that call into the .NET methods on .NET 9 or higher.
Add a couple of methods from System.IO.Path to PathUtilities:

- IsPathFullyQualified - Doesn't exist on net472 or netstandard2.0
- IsPathRooted - The overload that takes a ReadOnlySpan<char> (used by IsPathFullyQualfied) doesn't exist on net472 or netstandard2.0
In a prior implementation, DefaultRazorProjectFIleSystem.NormalizeAndEnsureValidPath(...) called Path.Combine(...) which would return the second path if both were rooted. However, that behavior was not carried into the new implementation, resulting in cases where a path can be "double" rooted if it is an absolute path outside of the project root. This change uses PathUtilities.IsPathFullQualified(...) to restore the previous behavior.
If ITagHelperResolver.GetTagHelpersAsync(...) fails, it returns a default (not empty) ImmutableArray<TagHelperDescriptor>. If that happens, we would end up throwing an exception when trying to report success telemetry by accessing the "Length" property on the result. This change checks first to see if the result was actually a failure and reports failure instead, avoiding the exception.
Recently, a couple of calls to RazorProjectFileSystem.GetItem(...) were changed to pass a file path rather than a target path. This results in an exception being thrown in the DefaultRazorProjectFileSystem if the file path is rooted outside of the project root. Instead, it's important to pass the "target path", i.e. the "logical" path of a file within the project. This avoids breaking completely valid scenarios where a file is included in the Razor project from an outside path (such as a content file in a NuGet package).
@DustinCampbell DustinCampbell requested review from a team as code owners May 16, 2025 16:09
@phil-allen-msft phil-allen-msft merged commit 8cce810 into release/dev17.14 May 16, 2025
11 checks passed
@phil-allen-msft phil-allen-msft deleted the dev/dustinca/backport-17.14-files-outside-project branch May 16, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants