mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Correcting issue in String::insert() where 0 offsets were handled incorrectly, affecting issue where values were not properly quoted and inserted into conditions strings. Fixes #6163.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8085 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
eea46e7cc8
commit
cb95f13608
5 changed files with 34 additions and 17 deletions
|
@ -1904,6 +1904,7 @@ class DboSource extends DataSource {
|
||||||
$key = substr($key, 0, $split);
|
$key = substr($key, 0, $split);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = (is_object($model) ? $model->getColumnType($key) : null);
|
$type = (is_object($model) ? $model->getColumnType($key) : null);
|
||||||
$null = ($value === null || (is_array($value) && empty($value)));
|
$null = ($value === null || (is_array($value) && empty($value)));
|
||||||
|
|
||||||
|
@ -1915,9 +1916,10 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
$value = $this->value($value, $type);
|
$value = $this->value($value, $type);
|
||||||
|
|
||||||
$key = (strpos($key, '(') !== false || strpos($key, ')') !== false) ?
|
if ($key !== '?') {
|
||||||
$this->__quoteFields($key) :
|
$isKey = (strpos($key, '(') !== false || strpos($key, ')') !== false);
|
||||||
$this->name($key);
|
$key = $isKey ? $this->__quoteFields($key) : $this->name($key);
|
||||||
|
}
|
||||||
|
|
||||||
if ($bound) {
|
if ($bound) {
|
||||||
return String::insert($key . ' ' . trim($operator), $value);
|
return String::insert($key . ' ' . trim($operator), $value);
|
||||||
|
|
|
@ -215,7 +215,7 @@ class Router extends Object {
|
||||||
return $_this->routes;
|
return $_this->routes;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*Specifies what named parameters CakePHP should be parsing. The most common setups are:
|
* Specifies what named parameters CakePHP should be parsing. The most common setups are:
|
||||||
*
|
*
|
||||||
* Do not parse any named parameters:
|
* Do not parse any named parameters:
|
||||||
* {{{ Router::connectNamed(false); }}}
|
* {{{ Router::connectNamed(false); }}}
|
||||||
|
|
|
@ -211,10 +211,10 @@ class String extends Object {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function insert($str, $data, $options = array()) {
|
function insert($str, $data, $options = array()) {
|
||||||
$options = array_merge(
|
$defaults = array(
|
||||||
array('before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false),
|
'before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false
|
||||||
$options
|
|
||||||
);
|
);
|
||||||
|
$options += $defaults;
|
||||||
$format = $options['format'];
|
$format = $options['format'];
|
||||||
|
|
||||||
if (!isset($format)) {
|
if (!isset($format)) {
|
||||||
|
@ -231,7 +231,7 @@ class String extends Object {
|
||||||
|
|
||||||
if (array_keys($data) === array_keys(array_values($data))) {
|
if (array_keys($data) === array_keys(array_values($data))) {
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
while ($pos = strpos($str, '?', $offset)) {
|
while (($pos = strpos($str, '?', $offset)) !== false) {
|
||||||
$val = array_shift($data);
|
$val = array_shift($data);
|
||||||
$offset = $pos + strlen($val);
|
$offset = $pos + strlen($val);
|
||||||
$str = substr_replace($str, $val, $pos, 1);
|
$str = substr_replace($str, $val, $pos, 1);
|
||||||
|
|
|
@ -2404,12 +2404,10 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$expected = " WHERE `client_id` > 20";
|
$expected = " WHERE `client_id` > 20";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->testDb->conditions(array(
|
$result = $this->testDb->conditions(array('OR' => array(
|
||||||
'OR' => array(
|
|
||||||
array('User.user' => 'mariano'),
|
array('User.user' => 'mariano'),
|
||||||
array('User.user' => 'nate')
|
array('User.user' => 'nate')
|
||||||
)
|
)));
|
||||||
));
|
|
||||||
|
|
||||||
$expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))";
|
$expected = " WHERE ((`User`.`user` = 'mariano') OR (`User`.`user` = 'nate'))";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -2545,6 +2543,12 @@ class DboSourceTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = ' WHERE ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN 65 AND 90';
|
$expected = ' WHERE ASCII(SUBSTRING(keyword, 1, 1)) BETWEEN 65 AND 90';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->testDb->conditions(array('or' => array(
|
||||||
|
'? BETWEEN Model.field1 AND Model.field2' => '2009-03-04'
|
||||||
|
)));
|
||||||
|
$expected = " WHERE '2009-03-04' BETWEEN Model.field1 AND Model.field2";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testArrayConditionsParsingComplexKeys method
|
* testArrayConditionsParsingComplexKeys method
|
||||||
|
|
|
@ -40,7 +40,8 @@ class StringTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testUuidGeneration() {
|
function testUuidGeneration() {
|
||||||
$result = String::uuid();
|
$result = String::uuid();
|
||||||
$match = preg_match("/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/", $result);
|
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
|
||||||
|
$match = preg_match($pattern, $result);
|
||||||
$this->assertTrue($match);
|
$this->assertTrue($match);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -52,9 +53,11 @@ class StringTest extends CakeTestCase {
|
||||||
function testMultipleUuidGeneration() {
|
function testMultipleUuidGeneration() {
|
||||||
$check = array();
|
$check = array();
|
||||||
$count = mt_rand(10, 1000);
|
$count = mt_rand(10, 1000);
|
||||||
|
$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for($i = 0; $i < $count; $i++) {
|
||||||
$result = String::uuid();
|
$result = String::uuid();
|
||||||
$match = preg_match("/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/", $result);
|
$match = preg_match($pattern, $result);
|
||||||
$this->assertTrue($match);
|
$this->assertTrue($match);
|
||||||
$this->assertFalse(in_array($result, $check));
|
$this->assertFalse(in_array($result, $check));
|
||||||
$check[] = $result;
|
$check[] = $result;
|
||||||
|
@ -179,9 +182,17 @@ class StringTest extends CakeTestCase {
|
||||||
$expected = "We are of course passing.";
|
$expected = "We are of course passing.";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = String::insert(':I.am: :not.yet: passing.', array('I.am' => 'We are'), array('before' => ':', 'after' => ':', 'clean' => true));
|
$result = String::insert(
|
||||||
|
':I.am: :not.yet: passing.',
|
||||||
|
array('I.am' => 'We are'),
|
||||||
|
array('before' => ':', 'after' => ':', 'clean' => true)
|
||||||
|
);
|
||||||
$expected = "We are passing.";
|
$expected = "We are passing.";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = String::insert('?-pended result', array('Pre'));
|
||||||
|
$expected = "Pre-pended result";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* test Clean Insert
|
* test Clean Insert
|
||||||
|
|
Loading…
Add table
Reference in a new issue