Skip to content

Fix XML parameter encoding for SQL Server - #38462

Merged
AndriySvyryd merged 10 commits into
mainfrom
copilot/fix-38429-sqlxml-parameters
Jun 23, 2026
Merged

AndriySvyryd merged 10 commits into
mainfrom
copilot/fix-38429-sqlxml-parameters

Conversation

Copilot AI commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38429

Unicode xml SQL literal: SqlServerStringTypeMapping now treats the xml store type as Unicode (_isUtf16 = true), so GenerateNonNullSqlLiteral emits an N-prefixed literal. It also sets DbType = Xml on the parameter and sends the value as SqlXml. Previously a non-Unicode (varchar) literal was generated for xml, silently losing non-ASCII content.

…rateNonNullSqlLiteral test

Co-authored-by: AndriySvyryd <[email protected]>
Copilot AI requested a review from AndriySvyryd June 19, 2026 02:53
@AndriySvyryd AndriySvyryd changed the title Move Xml_value_round_trips to BuiltInDataTypesSqlServerTest and harden the xml parameter XmlReader Fix XML parameter encoding for SQL Server Jun 19, 2026
@AndriySvyryd
AndriySvyryd requested a review from Copilot June 19, 2026 04:20

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.

Pull request overview

This PR improves SQL Server xml handling in EF Core by ensuring XML values are sent as SqlDbType.Xml (using SqlXml) and by hardening the XML parsing path against DTD/XXE-style payloads, with accompanying unit/functional test coverage.

Changes:

  • Update SQL Server string type mapping to treat xml as Unicode for SQL literal generation and to convert XML string parameters into SqlXml using secure XmlReaderSettings.
  • Update the SQL Server type mapping source so the xml mapping is explicitly configured with SqlDbType.Xml.
  • Add/extend tests to validate SqlXml parameterization, round-tripping behavior, and rejection of DTD payloads.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs Adds unit tests asserting xml parameters are sent as SqlDbType.Xml and values are SqlXml.
test/EFCore.SqlServer.FunctionalTests/BuiltInDataTypesSqlServerTest.cs Adds functional round-trip/query coverage for xml values and a negative test for DTD payload rejection; configures an xml-typed entity property in the fixture model.
src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs Configures the xml mapping with sqlDbType: SqlDbType.Xml so parameters can be sent correctly as XML.
src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs Adds secure XML reader settings and converts XML string parameters to SqlXml; adjusts Unicode literal handling for xml.

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review June 19, 2026 04:42
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner June 19, 2026 04:42
Copilot AI review requested due to automatic review settings June 19, 2026 04:42

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings June 19, 2026 06:25

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings June 19, 2026 22:07
@AndriySvyryd
AndriySvyryd force-pushed the copilot/fix-38429-sqlxml-parameters branch from 46e9376 to 3bfc384 Compare June 19, 2026 22:07

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

@AndriySvyryd
AndriySvyryd force-pushed the copilot/fix-38429-sqlxml-parameters branch from 3bfc384 to 9ef8296 Compare June 19, 2026 22:24
@AndriySvyryd
AndriySvyryd requested a review from cincuranet June 19, 2026 22:24
Copilot AI review requested due to automatic review settings June 22, 2026 17:12
@AndriySvyryd
AndriySvyryd requested a review from cincuranet June 22, 2026 17:14

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@AndriySvyryd
AndriySvyryd merged commit 3501892 into main Jun 23, 2026
14 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-38429-sqlxml-parameters branch June 23, 2026 17:42
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xml constants do not have the N prefix

5 participants