Skip to content

Translate string.TrimStart/TrimEnd with a char parameter instead of d… - #39105

Open
ilkertskn wants to merge 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-trim-char-parameter
Open

ilkertskn wants to merge 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-trim-char-parameter

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

…ropping it on SQL Server

On SQL Server 2022+ (compatibility level 160), TranslateTrimStartEnd accepts any single argument, but ProcessTrimStartEnd only handled SqlConstantExpression. A captured variable or parameter (var c = 'S'; ... x.TrimStart(c)) therefore fell through and the call was translated to the one-argument LTRIM(x), silently trimming whitespace instead of the requested character and returning wrong rows.

A non-constant char argument is now passed to LTRIM/RTRIM as a parameter with the char type mapping, and a non-constant char[] argument makes the translation fail (as SQLite already does) instead of being dropped.

Adds parameterized TrimStart/TrimEnd tests to StringTranslationsTestBase with SQL Server, SQLite and Cosmos overrides.

  • [x ] I've read the guidelines for contributing and seen the walkthrough
  • [x ] 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
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

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

…ropping it on SQL Server

On SQL Server 2022+ (compatibility level 160), TranslateTrimStartEnd accepts any
single argument, but ProcessTrimStartEnd only handled SqlConstantExpression. A
captured variable or parameter (`var c = 'S'; ... x.TrimStart(c)`) therefore fell
through and the call was translated to the one-argument `LTRIM(x)`, silently
trimming whitespace instead of the requested character and returning wrong rows.

A non-constant `char` argument is now passed to LTRIM/RTRIM as a parameter with
the char type mapping, and a non-constant `char[]` argument makes the translation
fail (as SQLite already does) instead of being dropped.

Adds parameterized TrimStart/TrimEnd tests to StringTranslationsTestBase with
SQL Server, SQLite and Cosmos overrides.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant