From 8868e833f41c6981d166baf46c7bc4b3baaed7bc Mon Sep 17 00:00:00 2001 From: Hichxm Date: Fri, 20 Oct 2023 02:56:10 +0200 Subject: [PATCH] fix: preg_replace evaluate double backslash for mysql driver and keep only one backslash instead of keep both backslash --- src/DataCollector/QueryCollector.php | 3 ++ tests/DataCollector/QueryCollectorTest.php | 51 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/DataCollector/QueryCollector.php b/src/DataCollector/QueryCollector.php index 2ca8cfcc2..a5a093634 100644 --- a/src/DataCollector/QueryCollector.php +++ b/src/DataCollector/QueryCollector.php @@ -161,6 +161,9 @@ public function addQuery($query, $bindings, $time, $connection) if ($pdo) { try { $binding = $pdo->quote((string) $binding); + + // Double escape backslashes because preg_replace evaluate backslashes + $binding = addcslashes($binding, "\\"); } catch (\Exception $e) { $binding = $this->emulateQuote($binding); } diff --git a/tests/DataCollector/QueryCollectorTest.php b/tests/DataCollector/QueryCollectorTest.php index 878fa20d3..ad5d4e900 100644 --- a/tests/DataCollector/QueryCollectorTest.php +++ b/tests/DataCollector/QueryCollectorTest.php @@ -2,7 +2,10 @@ namespace Barryvdh\Debugbar\Tests\DataCollector; +use Barryvdh\Debugbar\Tests\Models\Person; +use Barryvdh\Debugbar\Tests\Models\User; use Barryvdh\Debugbar\Tests\TestCase; +use Illuminate\Database\DatabaseManager; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Arr; @@ -58,4 +61,52 @@ public function testDollarBindingsArePresentedCorrectly() ); }); } + + public function testModelBindingsArePresentedCorrectlyWithSqliteDriver() + { + // Default connection "testing" running on sqlite pdo driver + + debugbar()->boot(); + + /** @var \Barryvdh\Debugbar\DataCollector\QueryCollector $collector */ + $collector = debugbar()->getCollector('queries'); + $collector->addQuery( + "SELECT a FROM b WHERE c = ? AND d = ? AND e = :user", + [User::class, Person::class, 'user' => User::class], + 0, + $this->app['db']->connection() + ); + + tap(Arr::first($collector->collect()['statements']), function (array $statement) { + $this->assertEquals(<<markTestSkipped('Unknown how to run only MySQL driver test (I dont know how to use pdo_mysql driver)'); + + debugbar()->boot(); + + /** @var \Barryvdh\Debugbar\DataCollector\QueryCollector $collector */ + $collector = debugbar()->getCollector('queries'); + $collector->addQuery( + "SELECT a FROM b WHERE c = ? AND d = ? AND e = :user", + [User::class, Person::class, 'user' => User::class], + 0, + $this->app['db']->connection() + ); + + tap(Arr::first($collector->collect()['statements']), function (array $statement) { + $this->assertEquals(<<