Skip to content

Commit

Permalink
MySqlDriver: fixed double escaped \ in formatLike() [Closes #147]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 1, 2016
1 parent 8e2a95e commit b74e9fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function formatDateInterval(\DateInterval $value)
*/
public function formatLike($value, $pos)
{
$value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
$value = addcslashes(substr($this->connection->quote($value), 1, -1), '%_');
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Database/Drivers/MySqlDriver.formatLike.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal(
Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField());
Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField());

Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField());
Assert::same(1, $connection->query("SELECT 'AA\\BB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField());

Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField());
Assert::same(1, $connection->query("SELECT 'AA\\%BB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField());

0 comments on commit b74e9fb

Please sign in to comment.