Skip to content

Commit 032b5ff

Browse files
authored
Fix binding with dollar not presented correctly in query (#1199)
1 parent 70b8975 commit 032b5ff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/DataCollector/QueryCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function addQuery($query, $bindings, $time, $connection)
164164
}
165165
}
166166

167-
$query = preg_replace($regex, $binding, $query, 1);
167+
$query = preg_replace($regex, addcslashes($binding, '$'), $query, 1);
168168
}
169169
}
170170

tests/DataCollector/QueryCollectorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,25 @@ public function testItReplacesQuestionMarksBindingsCorrectly()
3737
});
3838
});
3939
}
40+
41+
public function testDollarBindingsArePresentedCorrectly()
42+
{
43+
debugbar()->boot();
44+
45+
/** @var \Barryvdh\Debugbar\DataCollector\QueryCollector $collector */
46+
$collector = debugbar()->getCollector('queries');
47+
$collector->addQuery(
48+
"SELECT a FROM b WHERE c = ? AND d = ? AND e = ?",
49+
['$10', '$2y$10_DUMMY_BCRYPT_HASH', '$_$$_$$$_$2_$3'],
50+
0,
51+
$this->app['db']->connection()
52+
);
53+
54+
tap(Arr::first($collector->collect()['statements']), function (array $statement) {
55+
$this->assertEquals(
56+
"SELECT a FROM b WHERE c = '$10' AND d = '$2y$10_DUMMY_BCRYPT_HASH' AND e = '\$_$\$_$$\$_$2_$3'",
57+
$statement['sql']
58+
);
59+
});
60+
}
4061
}

0 commit comments

Comments
 (0)