From b74e9fb7a9f18dff6297a5c69e1f89c1837ffc4e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 1 Dec 2016 15:39:02 +0100 Subject: [PATCH] MySqlDriver: fixed double escaped \ in formatLike() [Closes #147] --- src/Database/Drivers/MySqlDriver.php | 2 +- tests/Database/Drivers/MySqlDriver.formatLike.phpt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Database/Drivers/MySqlDriver.php b/src/Database/Drivers/MySqlDriver.php index 001f486fa..a9a079e37 100644 --- a/src/Database/Drivers/MySqlDriver.php +++ b/src/Database/Drivers/MySqlDriver.php @@ -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 ? "%'" : "'"); } diff --git a/tests/Database/Drivers/MySqlDriver.formatLike.phpt b/tests/Database/Drivers/MySqlDriver.formatLike.phpt index 2cac97252..ab170e6a6 100644 --- a/tests/Database/Drivers/MySqlDriver.formatLike.phpt +++ b/tests/Database/Drivers/MySqlDriver.formatLike.phpt @@ -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());