Repository navigation
Don't escape quotes and apostrophes in scaffolded XML comments - #39536
Merged
AndriySvyryd merged 1 commit intoNov 13, 2026
Merged
Conversation
CSharpHelper.XmlComment escaped table and column comments with SecurityElement.Escape, which also turns ' and " into ' and ". Those characters aren't markup in XML text, so scaffolded documentation such as "user's machine" became "user's machine" in the source. - Escape only &, < and > in XmlComment, so the generated documentation stays valid XML while quotes and apostrophes remain readable - Add CSharpHelper and CSharpEntityTypeGenerator tests for comments with quotes, apostrophes, ampersands and markup Fixes dotnet#34714
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change preserving quotes and apostrophes in scaffolded C# XML documentation.
No open issues 🎉
What changed in this PR
Addresses #34714 by preserving quotes and apostrophes in scaffolded C# XML documentation, making database comments easier to read without changing XML markup escaping.
Changes:
- Replaces
SecurityElement.Escapewith escaping for only&,<, and>. - Adds helper-level and entity-scaffolding regression tests for quotes, apostrophes, and markup characters.
| File | Description |
|---|---|
| test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs | Verifies readable table and column comments in generated entity code. |
| test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs | Verifies that only XML markup characters are escaped. |
| src/EFCore.Design/Design/Internal/CSharpHelper.cs | Preserves quotes and apostrophes in XML comment text. |
Review effort: Balanced
AndriySvyryd
approved these changes
Nov 13, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
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 #34714
CSharpHelper.XmlCommentescaped table and column comments withSecurityElement.Escape, which also escapes'and". Neither is markup in XML text, so a column comment likeFilename under which map data are saved when cached on user's machine.was scaffolded asuser's machine. That's valid XML, but hard to read in the generated source.Fix
XmlCommentnow escapes only&,<and>. That's enough to keep the generated documentation valid XML.&and<must be escaped in XML text, and>is escaped as before. Quotes and apostrophes are now written as they are. Comments that contain markup, like<br/>, are still escaped (Comments_complex_are_generatedis unchanged).Tests
CSharpHelperTest.XmlComment_escapes_only_xml_markup_characters: quotes and apostrophes are kept, while&,<and>are escaped.CSharpEntityTypeGeneratorTest.Comments_with_quotes_and_ampersands_are_generated: scaffolds an entity whose table and column comments contain apostrophes, double quotes and&(the column comment is the one from the issue), and checks the generated file. The test harness also compiles the generated code.Both tests fail without the change. With it, all
EFCore.Design.Testspass locally (1347 passed, 1 skipped).Note that re-scaffolding a database whose comments contain quotes or apostrophes now produces slightly different (unescaped) XML comments.