From 85f2946c36668225bbc1678382abc6724a633c95 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 9 Apr 2008 02:24:09 +0000 Subject: [PATCH] "Fixes #4349, Correct usage of \"AND\" and \"and\" for conditions" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6641 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 4 +++- .../cases/libs/model/datasources/dbo_source.test.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 62d5e5044..909a48d89 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1698,7 +1698,9 @@ class DboSource extends DataSource { } else { if (!empty($match['2']) && $quoteValues) { $match['2'] = $this->value($match['2']); - $match['2'] = str_replace(' AND ', "' AND '", $match['2']); + if (preg_match('/^(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)/i', $match['1'])) { + $match['2'] = str_replace(' AND ', "' AND '", $match['2']); + } } $data = $this->__quoteFields($key); if ($data === $key) { 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 63901e1e0..81ab0f98d 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1467,6 +1467,16 @@ class DboSourceTest extends CakeTestCase { $result = $this->db->conditions($conditions); $expected = " WHERE `Company`.`name` like 'd.a%'"; $this->assertEqual($result, $expected); + + $conditions = array('Artist.name' => 'JUDY and MARY'); + $result = $this->db->conditions($conditions); + $expected = " WHERE `Artist`.`name` = 'JUDY and MARY'"; + $this->assertEqual($result, $expected); + + $conditions = array('Artist.name' => 'JUDY AND MARY'); + $result = $this->db->conditions($conditions); + $expected = " WHERE `Artist`.`name` = 'JUDY AND MARY'"; + $this->assertEqual($result, $expected); } function testQuotesInStringConditions() {