Skip to content

Commit

Permalink
[fix] buildRaw() with duplicate placeholder name #1069
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelaon committed Jan 22, 2024
1 parent 02877db commit dc3357b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ protected function buildRaw($raw, array &$map): ?string
}

$query = preg_replace_callback(
'/(([`\']).*?)?((FROM|TABLE|INTO|UPDATE|JOIN|TABLE IF EXISTS)\s*)?\<(([\p{L}_][\p{L}\p{N}@$#\-_]*)(\.[\p{L}_][\p{L}\p{N}@$#\-_]*)?)\>([^,]*?\2)?/u',
'/(([`\'])[\<]*?)?((FROM|TABLE|INTO|UPDATE|JOIN|TABLE IF EXISTS)\s*)?\<(([\p{L}_][\p{L}\p{N}@$#\-_]*)(\.[\p{L}_][\p{L}\p{N}@$#\-_]*)?)\>([^,]*?\2)?/',
function ($matches) {
if (!empty($matches[2]) && isset($matches[8])) {
return $matches[0];
Expand Down
23 changes: 23 additions & 0 deletions tests/RawTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,27 @@ public function testRawWithPlaceholder($type)
$this->database->queryString
);
}

/**
* @covers ::raw()
* @covers ::isRaw()
* @covers ::buildRaw()
* @dataProvider typesProvider
*/
public function testRawWithSamePlaceholderName($type)
{
$this->setType($type);

$this->database->select('account', [
'system' => Medoo::raw("COUNT(<system> = 'window' OR <system> = 'mac')")
]);

$this->assertQuery(
<<<EOD
SELECT COUNT("system" = 'window' OR "system" = 'mac') AS "system"
FROM "account"
EOD,
$this->database->queryString
);
}
}

0 comments on commit dc3357b

Please sign in to comment.