mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Single quotes should not be added to SQLFilter parameters #7075
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @geoffroyp on GitHub (Nov 28, 2022).
Bug Report
Summary
Greetings,
I think there's a weird behaviour in doctrine's filters. Possibly a bug.
When you you pass a parameter to SQLfilter, not only
$this->getParameter()returns it as a string, but two simple quotes are automatically added to this value. Therefore, all string methods, operators or casting that we could do on this value do not behave like we would expect.It's very confusing and could lead to all sort of bugs
Current behavior
in my file where I enable the filter
$this->em->getFilters()->enable('myFilter')->setParameter('myVar', 42);in the filter
Then $number is equal to 0, not 42 because it tries to cast
"'42'"to intin my file where I enable the filter
$this->em->getFilters()->enable('myFilter')->setParameter('myVar', null);in the filter
Then it will say that 'myVar is not empty', because it contains
"''", which I would definitely not expect by passing "null" as parameter...How to reproduce
see above.
Expected behavior
getParameter() should still return a string (even that could be up to debate, but I understand why it has been enforced), but it should NOT add those two single quotes
@numediaweb commented on GitHub (Jan 31, 2023):
Same issue here: quotes are a good security pass but it's creating issues with filters.
I ended up doing something like:
@luizpcam commented on GitHub (Mar 7, 2024):
same here .... :-(
@gregorybesson commented on GitHub (Mar 19, 2024):
+1 :)