diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 669ca474f..71a0599c6 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1348,14 +1348,16 @@ class DboSource extends DataSource { for($i = 0; $i < $pregCount; $i++) { if (!empty($match['1'][$i]) && !is_numeric($match['1'][$i])) { - $conditions = preg_replace('/^' . $match['0'][$i] . '/', ' '.$this->name($match['1'][$i]), $conditions); + $conditions = $conditions . ' '; + $conditions = preg_replace('/^' . $match['0'][$i] . '(?=[^\\w])/', ' '.$this->name($match['1'][$i]), $conditions); if (strpos($conditions, '(' . $match['0'][$i]) === false) { - $conditions = preg_replace('/[^\w]' . $match['0'][$i] . '/', ' '.$this->name($match['1'][$i]), $conditions); + $conditions = preg_replace('/[^\w]' . $match['0'][$i] . '(?=[^\\w])/', ' '.$this->name($match['1'][$i]), $conditions); } else { - $conditions = preg_replace('/' . $match['0'][$i] . '/', ' '.$this->name($match['1'][$i]), $conditions); + $conditions = preg_replace('/' . $match['0'][$i] . '(?=[^\\w])/', ' '.$this->name($match['1'][$i]), $conditions); } } } + $conditions = rtrim($conditions); } } return $clause . $conditions;