Skip to content
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

Backslashes are not always escaped when String.Contains is translated to LIKE #1943

Closed
doominator42 opened this issue Oct 17, 2024 · 0 comments · Fixed by #1951
Closed

Backslashes are not always escaped when String.Contains is translated to LIKE #1943

doominator42 opened this issue Oct 17, 2024 · 0 comments · Fixed by #1951

Comments

@doominator42
Copy link

Steps to reproduce

queryable.Where(e => e.StringProperty.Contains("\\"))

The issue

The escaping is wrong when using String.Contains("\\"). It gets translated to e.StringProperty LIKE '%\\%' (escaped only once, but should have been escaped twice for LIKE). Using String.Contains("\\%") correctly translates to e.StringProperty LIKE '%\\\\\\%%'.

By looking at the translator, it seems only strings with wildcard characters are escaped.

patternTransform(_sqlExpressionFactory.Constant($"%{(s.Any(IsLikeWildChar) ? EscapeLikePattern(s) : s)}%"))),

\ must be escaped too. There is the same issue for String.StartsWith and String.EndsWith.

Further technical details

MySQL version: 10.9.8-MariaDB-1:10.9.8+maria~ubu2204
Operating system: Arch Linux, Alpine Linux 3.20, Fedora 40
Pomelo.EntityFrameworkCore.MySql version: 8.0.2
Microsoft.AspNetCore.App version: 8.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment