Prevent odd document Uris from causing inadvertent syntax errors - #85886
Open
davidwengier wants to merge 3 commits into
Open
davidwengier wants to merge 3 commits into
davidwengier wants to merge 3 commits into
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The line-break regression test does not verify that each character receives the correct identity-preserving encoding.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Prevents virtual Razor document URIs from corrupting generated C# or causing incorrect file-kind detection.
Changes:
- Normalizes URI-shaped logical paths while preserving document identity.
- Safely escapes generated directives and metadata literals.
- Adds regression coverage for virtual documents and URI variants.
| File | Description |
|---|---|
.github/instructions/Razor.instructions.md |
Documents virtual-URI handling. |
FileUtilities.cs |
Adds URI-path normalization heuristics. |
CodeWriterExtensions.cs |
Escapes URI directive filenames. |
RazorCSharpDocumentWriter.cs |
Safely writes checksum paths. |
MetadataAttributeTargetExtension.cs |
Escapes metadata literals. |
FileKinds.cs |
Classifies normalized URI paths. |
RazorSourceGenerator.RazorProviders.cs |
Uses normalized logical project paths. |
SourceGeneratorProjectItem.cs |
Normalizes source relative paths. |
RazorSourceGeneratorVirtualDocumentTests.cs |
Tests virtual-document generation. |
FileKindsTest.cs |
Tests URI file-kind detection. |
MetadataAttributeTargetExtensionTest.cs |
Tests metadata escaping. |
CSharpCodeWriterTest.cs |
Tests directive URI encoding. |
This branch has not been deployed
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 dotnet/vscode-csharp#9831
For the left hand side of a diff, VS Code will create documents with Uris like
git://filename.razor?{"path":"filename.razor"}, and the quotes (and other things) can end up causing syntax errors due to them incorrectly terminating line directives, and at the same time our file kind detection can end up seeing the.razor?and falling back to the legacy (cshtml) file kind, which then can cause other errors because the directive set is different.This fixes both by encoding file paths as appropriate for generated C#, and using a method we already had to find the "real" file path from a Uri in a few more places.
Microsoft Reviewers: Open in CodeFlow