mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-06-22 02:34:08 +02:00
Fix random instances of SQL queries having params repeated (#505)
* Fix random instances of SQL queries having params repeated * Add test
This commit is contained in:
@ -123,7 +123,11 @@ class TracedStatement
|
||||
}
|
||||
|
||||
$matchRule = "/({$marker}(?!\w))(?=(?:[^$quotationChar]|[$quotationChar][^$quotationChar]*[$quotationChar])*$)/";
|
||||
for ($i = 0; $i <= mb_substr_count($sql, $k); $i++) {
|
||||
$count = mb_substr_count($sql, $k);
|
||||
if ($count < 1) {
|
||||
$count = mb_substr_count($sql, $matchRule);
|
||||
}
|
||||
for ($i = 0; $i <= $count; $i++) {
|
||||
$sql = preg_replace($matchRule, $v, $sql, 1);
|
||||
}
|
||||
}
|
||||
|
@ -150,4 +150,25 @@ class TracedStatementTest extends DebugBarTestCase
|
||||
$result = $traced->getSqlWithParams();
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that query parameters are being replaced only once
|
||||
* @bugFix Before fix it: select * from
|
||||
* `my_table` where `my_field` between
|
||||
* <2018-01-01> and <2018-01-01>
|
||||
* @return void
|
||||
*/
|
||||
public function testParametersAreNotRepeated()
|
||||
{
|
||||
$query = 'select * from `my_table` where `my_field` between ? and ?';
|
||||
$bindings = [
|
||||
'2018-01-01',
|
||||
'2020-09-01',
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
'select * from `my_table` where `my_field` between <2018-01-01> and <2020-09-01>',
|
||||
(new TracedStatement($query, $bindings))->getSqlWithParams()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user