Skip to content

Commit 00ef2a6

Browse files
committed
fix: resolve PostgreSQL select function with comma escape protection regression
1 parent 1a9882a commit 00ef2a6

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎system/Database/BaseBuilder.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function select($select = '*', ?bool $escape = null)
410410
}
411411

412412
if (is_string($select)) {
413-
$select = ($escape === false) ? [$select] : explode(',', $select);
413+
$select = ($escape === false) ? [$select] : preg_split('/,(?![^(]*\))/', $select);
414414
}
415415

416416
foreach ($select as $val) {

‎system/Database/BaseConnection.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
12801280
//
12811281
// Added exception for single quotes as well, we don't want to alter
12821282
// literal strings.
1283+
/** @psalm-suppress NoValue */
12831284
if (strcspn($item, "()'") !== strlen($item) && $this->isIdentifierEscapeExempt($item)) {
12841285
return $item;
12851286
}
@@ -1306,6 +1307,7 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
13061307
$alias = '';
13071308
}
13081309

1310+
/** @psalm-suppress NoValue */
13091311
if ($alias !== '' && strcspn($item, "()'") !== strlen($item) && $this->isIdentifierEscapeExempt($item)) {
13101312
return $item . $alias;
13111313
}
@@ -1496,6 +1498,7 @@ public function escapeIdentifiers($item)
14961498
return $item;
14971499
}
14981500

1501+
/** @psalm-suppress NoValue */
14991502
if (ctype_digit($item) || $this->isIdentifierEscapeExempt($item)) {
15001503
return $item;
15011504
}

‎tests/system/Database/BaseConnectionTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@ public static function provideProtectIdentifiers(): iterable
410410
'MAX("db"."payments") AS "payments"',
411411
],
412412

413+
'function with multiple arguments AS' => [
414+
false,
415+
true,
416+
true,
417+
"CONCAT(first_name, ' ', last_name) AS name",
418+
"CONCAT(first_name, ' ', last_name) AS name",
419+
],
420+
413421
'quoted column operator AS' => [
414422
false,
415423
true,

0 commit comments

Comments
 (0)