Skip to content

Commit

Permalink
Fix regular expressions in Database/Query
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton authored Mar 18, 2021
1 parent c9bb8f9 commit 2797039
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ public function getOriginalQuery(): string
*
* @return void
*
* @see https://regex101.com/r/jgAWNQ/2
* @see https://regex101.com/r/EUEhay/1 Test
*/
protected function compileBinds()
{
$sql = $this->finalQueryString;

$hasNamedBinds = preg_match('/\:(?:[\w\.\(\)]+)\:/', $sql) === 1;
$hasNamedBinds = preg_match('/:[a-z\d.)_(]+:/i', $sql) === 1;

if (empty($this->binds)
|| empty($this->bindMarker)
|| (strpos($sql, $this->bindMarker) === false && $hasNamedBinds === false)
|| (! $hasNamedBinds && strpos($sql, $this->bindMarker) === false)
)
{
return;
Expand Down Expand Up @@ -399,7 +399,7 @@ protected function matchNamedBinds(string $sql, array $binds): string
protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml): string
{
// Make sure not to replace a chunk inside a string that happens to match the bind marker
if ($c = preg_match_all("/'[^']*'/i", $sql, $matches))
if ($c = preg_match_all("/'[^']*'/", $sql, $matches))
{
$c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', str_replace($matches[0], str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE);

Expand Down

0 comments on commit 2797039

Please sign in to comment.