-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix up bugs in parsing special chracters in EditorConfig #54511
Conversation
2455390
to
b07df6e
Compare
bfae5c7
to
a62cfea
Compare
a62cfea
to
08a8780
Compare
@dotnet/roslyn-compiler Any chance I can get a review on this? This is blocking dotnet/website adopting the new Razor source generator and has been reported by a few customers in the previews. |
src/Compilers/Core/MSBuildTaskTests/GenerateMSBuildEditorConfigTests.cs
Outdated
Show resolved
Hide resolved
return string.IsNullOrEmpty(FileName.ItemSpec) ? true : WriteMSBuildEditorConfig(); | ||
} | ||
|
||
public bool WriteMSBuildEditorConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Assert.True(File.Exists(fileName)); | ||
Assert.Equal(expectedContents, File.ReadAllText(fileName)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to test that WriteMSBuildEditorConfig()
did not update the file if the contents were already correct, but it looks like It looks the method returns true
in either case.
Should we add an out bool updated
parameter that indicated whether the file was modified, and check that value?
} | ||
else | ||
{ | ||
sb.Append(lexer.CurrentCharacter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right. This path never gets hit. I'm not sure why I had this in the first place (perhaps something came up when I was doing the end-to-end testing with the dotnet/website repo), but it's not needed. CanGetSectionsWithSpecialCharacters
still passes without this.
Can this be merged or are there other things to sort out? Hoping to ship this fix alongside rc1. |
Thanks @captainsafia for fixing this. |
Resolves issues like dotnet/aspnetcore#33832 and #51692.
Follow-up to #52515.
Changes in this PR
WriteLinesToFile
task to write the editor config to disk and write to disk insideGenerateMSBuildConfigEditor
task.Moving from C# to MSBuild to EditorConfig causes a lot of weird issues when writing editorconfigs with special characters mostly due to MSBuild's behavior in certain scenarios.
Given all this, I think it makes sense to move the file writes to inside the
GenerateMSBuildConfigEditor
task to avoid issues that come up because of the interop between C# strings, MSBuild strings, and editorconfig's requirements.GetSectionFromSource
.Validations