Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

Q A
Branch? 4.2
Tickets Closes #..., closes #...
License MIT
Doc PR api-platform/docs#...

% and _ are reserved characters which need to be escaped when used in a LIKE query.

Before this PR '/chickens?namePartial=%', returns 2 results ; now it correctly returns 0.

'LOWER('.$field.')',
':'.$parameterName
));
$likeExpression = 'LOWER('.$field.') LIKE :'.$parameterName.' ESCAPE \'\\\'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used ESCAPE is this compatible with all the doctrine platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot be fully sure and I'm open to feedback about it. But this seems to be a basic "SQL" clause.

On the other side, I couldn't make the tests to work with the initial

$queryBuilder->expr()->like

The issue was that the test run on pdo sqlite which had trouble with a search like \ ; seems like \ is not the character used by default to escape like search for pdo sqlite (while it worked fine on mysql and pgsql).

So the other solution was to keep $queryBuilder->expr()->like( and

  • ignoring the test for \
  • not being sure that \ was used to escape on every existing platform.

This didn't seem better to me

@soyuka soyuka changed the title Fix PartialSearchFilter for values with % or _ fix(doctrine): escape values with % or _ in search filter Jan 8, 2026
@soyuka soyuka merged commit 550b762 into api-platform:4.2 Jan 8, 2026
130 checks passed
@soyuka
Copy link
Member

soyuka commented Jan 8, 2026

Thanks!

@VincentLanglet
Copy link
Contributor Author

Thanks!

You're welcome ; should we backport this fix to the SearchFilter ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants