Fix crash when Data Source starts with a comma#3250
Fix crash when Data Source starts with a comma#3250paulmedynski merged 2 commits intodotnet:mainfrom
Conversation
|
@dotnet-policy-service agree |
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs
Outdated
Show resolved
Hide resolved
paulmedynski
left a comment
There was a problem hiding this comment.
Great fisrt open-source contribution! Little bugs like these can be very frustrating for users, so we appreciate you taking the time to fix one :)
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs
Outdated
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@paulmedynski Thank you for the feedback, it helps a lot 😄 I've updated the test name and replaced Record.Exception with Assert.Throws() as suggested. Let me know if you'd like anything else adjusted — happy to improve further! |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
paulmedynski
left a comment
There was a problem hiding this comment.
Changes look great - thanks!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3250 +/- ##
==========================================
- Coverage 72.69% 0 -72.70%
==========================================
Files 303 0 -303
Lines 59718 0 -59718
==========================================
- Hits 43414 0 -43414
+ Misses 16304 0 -16304
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #3110
this PR fixes a crash in
ADP.IsEndpoint(...)caused by an unsafe call toLastIndexOf('\\', length - 1, length - 1)when the Data Source in the connection string starts with a comma (e.g."Data Source=,").When
length == 0, the method would previously throw anArgumentOutOfRangeException.---Fix
Added a defensive check to ensure
length > 0before callingLastIndexOf, which prevents invalid index access.--- Tests
ConnectionString_WithOnlyComma_ShouldNotThrowThis is my first open-source contribution — excited to be part of the project! Let me know if you'd like any changes.