diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index f0181b422..16187bda5 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1569,7 +1569,7 @@ class DboSource extends DataSource { $data = $this->name($key) . " = " . $this->boolean($value); } elseif ($value === '') { $data = $this->name($key) . " = ''"; - } elseif (preg_match('/^([a-z]*\\([a-z0-9]*\\)\\x20?|(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)?(.*)/i', $value, $match)) { + } elseif (preg_match('/^([a-z]+\\([a-z0-9]*\\)\\x20+|(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)?(.*)/i', $value, $match)) { if (preg_match('/(\\x20[\\w]*\\x20)/', $key, $regs)) { $clause = $regs['1']; $key = preg_replace('/' . $regs['1'] . '/', '', $key); @@ -1581,6 +1581,9 @@ class DboSource extends DataSource { } elseif (empty($mValue)) { $match['1'] = ' = '; $match['2'] = $match['0']; + } elseif(!isset($match['2'])) { + $match['1'] = ' = '; + $match['2'] = $match['0']; } if (strpos($match['2'], '-!') === 0) { @@ -1588,7 +1591,7 @@ class DboSource extends DataSource { $data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2']; } else { if (!empty($match['2']) && $quoteValues) { - if (strpos($match['2'], '()') === false) { + if(!preg_match('/[A-Za-z]+\\([a-z0-9]*\\),?\\x20+/', $match['2'])) { $match['2'] = $this->value($match['2']); } $match['2'] = str_replace(' AND ', "' AND '", $match['2']); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 2efb09f54..a506ebe08 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1469,9 +1469,9 @@ class DboSourceTest extends UnitTestCase { $result = $this->db->conditions(array('id' => '<> 8')); $this->assertPattern('/^\s*WHERE\s+`id`\s+<>\s+8\s*$/', $result); - //$result = $this->db->conditions(array('TestModel.field' => '= gribe$@()lu')); - //$expected = " WHERE `TestModel.field` = 'gribe$@()lu'"; - //$this->assertEqual($result, $expected); + $result = $this->db->conditions(array('TestModel.field' => '= gribe$@()lu')); + $expected = " WHERE `TestModel`.`field` = 'gribe$@()lu'"; + $this->assertEqual($result, $expected); } function testFieldParsing() {