Skip to content

Commit a7fc507

Browse files
committed
refactor: simplify conditions in BaseConnection using Rector
1 parent a3df98f commit a7fc507

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,8 @@ 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-
if (strcspn($item, "()'") !== strlen($item)) {
1284-
if ($this->isIdentifierEscapeExempt($item)) {
1285-
return $item;
1286-
}
1283+
if (strcspn($item, "()'") !== strlen($item) && $this->isIdentifierEscapeExempt($item)) {
1284+
return $item;
12871285
}
12881286

12891287
// Do not protect identifiers and do not prefix, no swap prefix, there is nothing to do
@@ -1454,16 +1452,9 @@ private function isIdentifierEscapeExempt(string $item): bool
14541452
if ($this->escapeChar !== '"' && $item[0] === '"' && preg_match('/^"(?:[^"]|"")*"$/s', $item)) {
14551453
return true;
14561454
}
1457-
14581455
// SQL functions or subqueries (e.g. MAX(id), (SELECT ...)) with an optional alias
1459-
if (str_contains($item, '(')) {
1460-
// Regex matching balanced parentheses (from start to end or with a safe alias)
1461-
if (preg_match('/^(?:[a-zA-Z0-9_.]+\s*)?(?P<parens>\((?:[^()]+|(?&parens))*\))(?:\s+AS\s+(?:[a-zA-Z0-9_.]+|"[^"]*"|\'[^\']*\'|`[^`]*`))?$/is', $item)) {
1462-
return true;
1463-
}
1464-
}
1465-
1466-
return false;
1456+
// Regex matching balanced parentheses (from start to end or with a safe alias)
1457+
return str_contains($item, '(') && preg_match('/^(?:[a-zA-Z0-9_.]+\s*)?(?P<parens>\((?:[^()]+|(?&parens))*\))(?:\s+AS\s+(?:[a-zA-Z0-9_.]+|"[^"]*"|\'[^\']*\'|`[^`]*`))?$/is', $item);
14671458
}
14681459

14691460
/**

0 commit comments

Comments
 (0)