Backport LIKE escape mapping fix to 10.0#3891
Merged
Merged
Conversation
Keep LIKE and ILIKE escape expressions independent from match and pattern type mapping so property converters cannot rewrite provider-generated escape values. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e5b861c2-ea5b-411c-8efe-3d925d29c52e
Preserve null escape expressions before applying default type mapping for LIKE and ILIKE. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e5b861c2-ea5b-411c-8efe-3d925d29c52e
Use the hotfix branch's InitializeAsync and CreateContext helpers for the backported regression test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e5b861c2-ea5b-411c-8efe-3d925d29c52e
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Backports the fix for #3888 to prevent a LIKE/ILIKE match property’s value converter from being applied to the provider-generated escape expression, which could lead to ESCAPE NULL and “unknown” predicate results.
Changes:
- Adjust type-mapping application for
LikeExpressionandPgILikeExpressionso the escape character mapping is independent from match/pattern inference. - Add a regression test verifying implicit escape does not apply the value converter for both LIKE and ILIKE.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.PG.FunctionalTests/Query/AdHocMiscellaneousQueryNpgsqlTest.cs | Adds regression coverage for implicit escape handling with a value-converted property. |
| src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs | Updates type mapping logic to avoid propagating converters onto escape expressions for LIKE/ILIKE. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Comment on lines
+714
to
739
| // The base implementation is private, so duplicate it here to keep the escape character's type mapping independent. | ||
| private SqlExpression ApplyTypeMappingOnLike(LikeExpression likeExpression) | ||
| { | ||
| var inferredTypeMapping = ExpressionExtensions.InferTypeMapping(likeExpression.Match, likeExpression.Pattern) | ||
| ?? _typeMappingSource.FindMapping(likeExpression.Match.Type, Dependencies.Model); | ||
|
|
||
| return new LikeExpression( | ||
| ApplyTypeMapping(likeExpression.Match, inferredTypeMapping), | ||
| ApplyTypeMapping(likeExpression.Pattern, inferredTypeMapping), | ||
| // The escape character must not inherit the match or pattern's value converter (#3888). | ||
| likeExpression.EscapeChar is null ? null : ApplyDefaultTypeMapping(likeExpression.EscapeChar), | ||
| _boolTypeMapping); | ||
| } | ||
|
|
||
| private SqlExpression ApplyTypeMappingOnILike(PgILikeExpression ilikeExpression) | ||
| { | ||
| var inferredTypeMapping = (ilikeExpression.EscapeChar is null | ||
| ? ExpressionExtensions.InferTypeMapping( | ||
| ilikeExpression.Match, ilikeExpression.Pattern) | ||
| : ExpressionExtensions.InferTypeMapping( | ||
| ilikeExpression.Match, ilikeExpression.Pattern, | ||
| ilikeExpression.EscapeChar)) | ||
| var inferredTypeMapping = ExpressionExtensions.InferTypeMapping(ilikeExpression.Match, ilikeExpression.Pattern) | ||
| ?? _typeMappingSource.FindMapping(ilikeExpression.Match.Type, Dependencies.Model); | ||
|
|
||
| return new PgILikeExpression( | ||
| ApplyTypeMapping(ilikeExpression.Match, inferredTypeMapping), | ||
| ApplyTypeMapping(ilikeExpression.Pattern, inferredTypeMapping), | ||
| ApplyTypeMapping(ilikeExpression.EscapeChar, inferredTypeMapping), | ||
| // The escape character must not inherit the match or pattern's value converter (#3888). | ||
| ilikeExpression.EscapeChar is null ? null : ApplyDefaultTypeMapping(ilikeExpression.EscapeChar), | ||
| _boolTypeMapping); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #3889 and #3890 to the
hotfix/10.0.3branch.A value converter on a LIKE/ILIKE match property could be applied to the escape expression, converting the provider-generated empty escape into
ESCAPE NULLand causing matching predicates to evaluate as unknown. This keeps escape-character type mapping independent from match/pattern inference for both LIKE and ILIKE, while explicitly preserving an absent optional escape.The regression test is adapted to the 10.0 branch's
InitializeAsynctest infrastructure.Tests:
NorthwindDbFunctionsQueryNpgsqlTestAdHocMiscellaneousQueryNpgsqlTest.Like_with_implicit_escape_does_not_apply_value_converterFixes: #3888