Skip to content

Port#3399 to release/5.2 #3407

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

Open
wants to merge 1 commit into
base: release/5.2
Choose a base branch
from
Open

Conversation

apoorvdeshmukh
Copy link
Contributor

@apoorvdeshmukh apoorvdeshmukh commented Jun 11, 2025

Description

This is a port of #3399 for release/5.2

Issues

#3397

Testing

This port also contains the testcase to validate the fix.

Additional Notes

For local validation on 5.2,
Have net 6.0 installed. Build all targets (BuildAllConfigurations, buildtestsnetcore) with -p:TF=net60 so that ManualTesting.dll is correctly generated.

@apoorvdeshmukh apoorvdeshmukh requested review from Copilot and a team June 11, 2025 05:49
Copy link
Contributor

@Copilot Copilot AI left a comment

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 ports the BOM-free UTF-8 fix (#3399) into both .NET Framework and .NET Core parsers, and adds a manual test to validate UTF-8 bulk copy behavior.

  • Introduces s_utf8EncodingWithoutBom in TdsParser for netfx and netcore and replaces all Encoding.UTF8 uses.
  • Adds TestBulkCopyWithUTF8 manual test and includes it in the test project.
  • Introduces DataTestUtility.CreateTable helper for table setup in tests.

Reviewed Changes

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

Show a summary per file
File Description
src/.../SqlBulkCopyTest/TestBulkCopyWithUTF8.cs New manual test for UTF-8 behavior
src/.../ManualTesting.Tests.csproj Included the new test in the project file
src/.../DataCommon/DataTestUtility.cs Added CreateTable helper
src/.../netfx/src/.../TdsParser.cs Introduced non-BOM UTF8 encoding and replaced uses
src/.../netcore/src/.../TdsParser.cs Introduced non-BOM UTF8 encoding and replaced uses
Comments suppressed due to low confidence (4)

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/TestBulkCopyWithUTF8.cs:12

  • [nitpick] Class name casing is inconsistent with the file name (TestBulkCopyWithUTF8.cs). Consider renaming to TestBulkCopyWithUTF8 for clarity and consistency.
public sealed class TestBulkCopyWithUtf8 : IDisposable

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/TestBulkCopyWithUTF8.cs:112

  • xUnit does not provide Assert.Fail. To explicitly fail, use Assert.True(false, message) or throw a XunitException with the failure message.
Assert.Fail($"Bulk copy failed: {ex.Message}");

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/TestBulkCopyWithUTF8.cs:176

  • xUnit does not provide Assert.Fail. To explicitly fail, use Assert.True(false, message) or throw a XunitException with the failure message.
Assert.Fail($"Bulk copy failed: {ex.Message}");

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs:593

  • Building SQL with raw tableName concatenation can risk SQL injection or invalid identifiers. Consider wrapping tableName in QUOTENAME or otherwise quoting it safely.
public static void CreateTable(SqlConnection sqlConnection, string tableName, string createBody)

@apoorvdeshmukh apoorvdeshmukh changed the title Use UTF8 instance that doesn't emit BOM Port#3399 : Use UTF8 instance that doesn't emit BOM Jun 11, 2025
@apoorvdeshmukh apoorvdeshmukh changed the title Port#3399 : Use UTF8 instance that doesn't emit BOM Port#3399 to release/5.2 Jun 11, 2025
Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

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

CI build failures.

@@ -0,0 +1,196 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license preamble.

DataTestUtility.CreateTable(connection, destinationTable, columnDefinition);
using SqlCommand insertCommand = connection.CreateCommand();
insertCommand.CommandText = insertQuery;
Helpers.TryExecute(insertCommand, insertQuery);
Copy link
Contributor

Choose a reason for hiding this comment

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

CI says Helpers is not found for some builds.

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.

3 participants