Don't replace the slashes in hint names#12477
Merged
chsienki merged 9 commits intodotnet:mainfrom Nov 19, 2025
Merged
Conversation
chsienki
commented
Nov 11, 2025
| { | ||
| switch (filePath[i]) | ||
| { | ||
| case ':' or '\\' or '/': |
Member
Author
There was a problem hiding this comment.
':' is covered by the case below anyway.
Member
davidwengier
left a comment
There was a problem hiding this comment.
I would have thought tests in ComputedTargetPathTest.cs would fail with this, at least.
Either way, can you add this test. I haven't run it, obviously, but it fails without your change, and I think it should pass with it.
[Theory]
[InlineData(true, false)]
[InlineData(true, true)]
[InlineData(false, false)]
public async Task TwoDocumentsWithTheSameBaseHintName(bool projectPath, bool generateConfigFile)
{
var builder = new RazorProjectBuilder
{
ProjectFilePath = projectPath ? TestProjectData.SomeProject.FilePath : null,
GenerateGlobalConfigFile = generateConfigFile,
GenerateAdditionalDocumentMetadata = false,
GenerateMSBuildProjectDirectory = false
};
var doc1Id = builder.AddAdditionalDocument(FilePath(@"Pages\Index.razor"), SourceText.From(""));
var doc2Id = builder.AddAdditionalDocument(FilePath(@"Pages_Index.razor"), SourceText.From(""));
var solution = LocalWorkspace.CurrentSolution;
solution = builder.Build(solution);
var doc1 = solution.GetAdditionalDocument(doc1Id).AssumeNotNull();
var doc2 = solution.GetAdditionalDocument(doc2Id).AssumeNotNull();
var generatedDocument = await doc1.Project.TryGetSourceGeneratedDocumentForRazorDocumentAsync(doc1, DisposalToken);
Assert.NotNull(generatedDocument);
Assert.Equal($"{s_hintNamePrefix}_Pages\\Index_razor.g.cs", generatedDocument.HintName);
generatedDocument = await doc2.Project.TryGetSourceGeneratedDocumentForRazorDocumentAsync(doc2, DisposalToken);
Assert.NotNull(generatedDocument);
Assert.Equal($"{s_hintNamePrefix}_Pages_Index_razor.g.cs", generatedDocument.HintName);
}
Member
Author
|
@davidwengier Ah they do, I just didn't see them because I was only running the net8.0 tests. Will add the extra test. |
davidwengier
approved these changes
Nov 12, 2025
Member
davidwengier
left a comment
There was a problem hiding this comment.
LGTM, on the assumption that the remaining test failures are just things in need of infra or baseline updates
chsienki
commented
Nov 12, 2025
src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs
Outdated
Show resolved
Hide resolved
chsienki
commented
Nov 12, 2025
src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs
Outdated
Show resolved
Hide resolved
chsienki
commented
Nov 12, 2025
src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs
Outdated
Show resolved
Hide resolved
This was referenced Nov 19, 2025
This was referenced Dec 12, 2025
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 #11578
When the generator was originally written slashes were not allowed in hint names. That restriction was subsequently lifted, and they are valid parts of a hint name now. See here.