Adding fixes for test added in [4911] and [4912]

Fixed #2414 fixes findBy doesn't escape WHERE condition

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4913 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-04-29 05:37:39 +00:00
parent 6978359505
commit 5757d6b7e9
2 changed files with 8 additions and 5 deletions

View file

@ -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']);

View file

@ -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() {