mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing conditions quoting in DboSource::conditionKeysToString(), closes #4368
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6691 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d8cb269dc3
commit
3e28323667
2 changed files with 27 additions and 4 deletions
|
@ -1704,6 +1704,7 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
$not = false;
|
$not = false;
|
||||||
$mValue = trim($match['1']);
|
$mValue = trim($match['1']);
|
||||||
|
|
||||||
if (empty($match['1'])) {
|
if (empty($match['1'])) {
|
||||||
$match['1'] = ' = ';
|
$match['1'] = ' = ';
|
||||||
} elseif (empty($mValue)) {
|
} elseif (empty($mValue)) {
|
||||||
|
@ -1722,10 +1723,16 @@ class DboSource extends DataSource {
|
||||||
$match['2'] = str_replace('-!', '', $match['2']);
|
$match['2'] = str_replace('-!', '', $match['2']);
|
||||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||||
} else {
|
} else {
|
||||||
|
$op = substr(trim($match[1]), 0, 1);
|
||||||
|
|
||||||
if (!empty($match['2']) && $quoteValues) {
|
if (!empty($match['2']) && $quoteValues) {
|
||||||
$match['2'] = $this->value($match['2']);
|
if (!in_array($op, str_split('!=<>')) && !in_array(strtolower(trim($match[1])), $this->__sqlOps)) {
|
||||||
if (preg_match('/^(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)/i', $match['1'])) {
|
$match['1'] = ' = ';
|
||||||
$match['2'] = str_replace(' AND ', "' AND '", $match['2']);
|
$match['2'] = $this->value($match['0']);
|
||||||
|
} elseif (preg_match('/^(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)/i', $match['1'])) {
|
||||||
|
$match['2'] = str_replace(' AND ', "' AND '", $this->value($match['2']));
|
||||||
|
} else {
|
||||||
|
$match['2'] = $this->value($match['2']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data = $this->__quoteFields($key);
|
$data = $this->__quoteFields($key);
|
||||||
|
|
|
@ -32,6 +32,7 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||||
|
|
||||||
uses('model'.DS.'model', 'model'.DS.'datasources'.DS.'datasource',
|
uses('model'.DS.'model', 'model'.DS.'datasources'.DS.'datasource',
|
||||||
'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_mysql');
|
'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_mysql');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
@ -593,6 +594,7 @@ class DboTest extends DboMysql {
|
||||||
* @subpackage cake.tests.cases.libs.model.datasources
|
* @subpackage cake.tests.cases.libs.model.datasources
|
||||||
*/
|
*/
|
||||||
class DboSourceTest extends CakeTestCase {
|
class DboSourceTest extends CakeTestCase {
|
||||||
|
|
||||||
var $debug = null;
|
var $debug = null;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
|
@ -1711,6 +1713,21 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$result = $this->db->conditions($conditions);
|
$result = $this->db->conditions($conditions);
|
||||||
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76) ";
|
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76) ";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$conditions = array('title' => 'user(s)');
|
||||||
|
$result = $this->db->conditions($conditions);
|
||||||
|
$expected = " WHERE `title` = 'user(s)'";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$conditions = array('title' => 'user(s) data');
|
||||||
|
$result = $this->db->conditions($conditions);
|
||||||
|
$expected = " WHERE `title` = 'user(s) data'";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$conditions = array('title' => 'user(s,arg) data');
|
||||||
|
$result = $this->db->conditions($conditions);
|
||||||
|
$expected = " WHERE `title` = 'user(s,arg) data'";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMixedConditionsParsing() {
|
function testMixedConditionsParsing() {
|
||||||
|
@ -2175,7 +2192,6 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$result = $this->db->calculate($this->Model, 'max', array('`Model`.`id`', 'id'));
|
$result = $this->db->calculate($this->Model, 'max', array('`Model`.`id`', 'id'));
|
||||||
$this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`');
|
$this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue