Skip to content

Commit

Permalink
loosen regex to allow nested function calls in sql
Browse files Browse the repository at this point in the history
this essentially is a recursive regex to ensure balanced parantheses
  • Loading branch information
globin authored and Dimitris Giotas committed Jun 17, 2016
1 parent 48cc7d7 commit 820c728
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Db/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public function group($spec)
}

foreach ($spec as $val) {
if (preg_match('/^[\w]*\([^\)]*\)$/', (string) $val)) {
if (preg_match('/^([\w]*\(([^\)]|(?1))*\))$/', (string) $val)) {
$val = new Zend_Db_Expr($val);
}
$this->_parts[self::GROUP][] = $val;
Expand Down Expand Up @@ -601,7 +601,7 @@ public function order($spec)
$val = trim($matches[1]);
$direction = $matches[2];
}
if (preg_match('/^[\w]*\([^\)]*\)$/', $val)) {
if (preg_match('/^([\w]*\(([^\)]|(?1))*\))$/', (string) $val)) {
$val = new Zend_Db_Expr($val);
}
$this->_parts[self::ORDER][] = array($val, $direction);
Expand Down Expand Up @@ -943,7 +943,7 @@ protected function _tableCols($correlationName, $cols, $afterCorrelationName = n
$alias = $m[2];
}
// Check for columns that look like functions and convert to Zend_Db_Expr
if (preg_match('/^[\w]*\([^\)]*\)$/', $col)) {
if (preg_match('/^([\w]*\(([^\)]|(?1))*\))$/', (string) $col)) {
$col = new Zend_Db_Expr($col);
} elseif (preg_match('/(.+)\.(.+)/', $col, $m)) {
$currentCorrelationName = $m[1];
Expand Down

0 comments on commit 820c728

Please sign in to comment.