[SqlClient] Skip N from unicode strings when sanitizing queries#3662
[SqlClient] Skip N from unicode strings when sanitizing queries#3662alanwest merged 4 commits intoopen-telemetry:mainfrom
Conversation
Skip leading `N` in values of the form `N'foo'`. Resolves open-telemetry#3659.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3662 +/- ##
==========================================
+ Coverage 71.55% 71.62% +0.06%
==========================================
Files 455 455
Lines 17639 17642 +3
==========================================
+ Hits 12622 12636 +14
+ Misses 5017 5006 -11 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Add changes to EFCore and SqlClient CHANGELOGs.
Use a constant for the prefix and expand on the comment.
There was a problem hiding this comment.
Pull request overview
This pull request fixes SQL query sanitization to properly handle Unicode string literals in T-SQL. Previously, when sanitizing queries containing Unicode strings of the form N'text', the leading N prefix was retained, resulting in N? instead of ?. This change ensures the Unicode prefix is removed during sanitization.
Key Changes:
- Added detection logic to identify Unicode string literals (prefixed with
N) - Implemented buffer position adjustment to remove the Unicode prefix when sanitizing
- Updated test case expectations to reflect correct sanitization behavior without the
Nprefix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Shared/SqlProcessor.cs | Added Unicode prefix detection and buffer position adjustment in string literal sanitization logic |
| test/OpenTelemetry.Contrib.Shared.Tests/SqlProcessorAdditionalTestCases.json | Updated existing test case expectation and added new test case for Unicode string literals |
| src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md | Documented the Unicode string literal sanitization improvement |
| src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md | Documented the Unicode string literal sanitization improvement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ccfe01c
Resolves #3659.
Changes
Skip leading
Nin values of the formN'foo'to avoid sanitized queries containingN?values.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)