Skip to content

Don't escape quotes and apostrophes in scaffolded XML comments - #39536

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
officialasishkumar:fix/34714-xml-comment-escaping
Nov 13, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
officialasishkumar:fix/34714-xml-comment-escaping

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Fixes #34714

CSharpHelper.XmlComment escaped table and column comments with SecurityElement.Escape, which also escapes ' and ". Neither is markup in XML text, so a column comment like Filename under which map data are saved when cached on user's machine. was scaffolded as user's machine. That's valid XML, but hard to read in the generated source.

Fix

XmlComment now 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_generated is 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.Tests pass locally (1347 passed, 1 skipped).

Note that re-scaffolding a database whose comments contain quotes or apostrophes now produces slightly different (unescaped) XML comments.

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

CSharpHelper.XmlComment escaped table and column comments with
SecurityElement.Escape, which also turns ' and " into &apos; and &quot;.
Those characters aren't markup in XML text, so scaffolded documentation
such as "user's machine" became "user&apos;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
@officialasishkumar
officialasishkumar requested a review from a team as a code owner November 5, 2026 14:41
Copilot AI balanced review requested due to automatic review settings November 5, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.Escape with 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 AndriySvyryd self-assigned this Nov 7, 2026

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 4c991ed into dotnet:main Nov 13, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apostrophe symbol in SQL Server column description is scaffolded as &apos;

3 participants