FaaPz/PDO

Bad where clause construction

Closed this issue · 1 comments

https://github.com/FaaPz/Slim-PDO/blob/2eaaae8c5fbfeba832bf3c8fa88b1780e23554ee/src/PDO/Clause/WhereClause.php#L231

ltrim should not be used here. ltrim removes any of the characters in the second parameter starting from left until it encounters another character.
So if you have a field starting with capital 'A', 'N' or 'D', this first char will be removed.

preg_replace should be used instead to remove the first ' AND ':

return ' WHERE ' . preg_replace('/^(\sAND\s)/', '', implode('', $args));

kwhat commented

Hi Brewal,

Thanks for the report. This is def an oversight that would cause some seriously hard to debug issues. I have updated the 2.x branch with your suggested update and replaced a few more (less critical) rtrim calls with preg_replace. Changes are covered here: 2c06e83