Skip to content

Commit b74e9fb

Browse files
committed
MySqlDriver: fixed double escaped \ in formatLike() [Closes #147]
1 parent 8e2a95e commit b74e9fb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Database/Drivers/MySqlDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function formatDateInterval(\DateInterval $value)
114114
*/
115115
public function formatLike($value, $pos)
116116
{
117-
$value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
117+
$value = addcslashes(substr($this->connection->quote($value), 1, -1), '%_');
118118
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
119119
}
120120

tests/Database/Drivers/MySqlDriver.formatLike.phpt

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal(
2323
Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField());
2424
Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField());
2525

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

0 commit comments

Comments
 (0)