mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #11283 from chinpei215/2.x-cookie-component-1
[2.x] Fix fatal error thrown when replacing scalar with array
This commit is contained in:
commit
a71cad0420
2 changed files with 23 additions and 18 deletions
|
@ -229,27 +229,14 @@ class CookieComponent extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($key as $name => $value) {
|
foreach ($key as $name => $value) {
|
||||||
$names = array($name);
|
|
||||||
if (strpos($name, '.') !== false) {
|
if (strpos($name, '.') !== false) {
|
||||||
$names = explode('.', $name, 2);
|
$this->_values[$this->name] = Hash::insert($this->_values[$this->name], $name, $value);
|
||||||
}
|
list($name) = explode('.', $name, 2);
|
||||||
$firstName = $names[0];
|
$value = $this->_values[$this->name][$name];
|
||||||
$isMultiValue = (is_array($value) || count($names) > 1);
|
|
||||||
|
|
||||||
if (!isset($this->_values[$this->name][$firstName]) && $isMultiValue) {
|
|
||||||
$this->_values[$this->name][$firstName] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($names) > 1) {
|
|
||||||
$this->_values[$this->name][$firstName] = Hash::insert(
|
|
||||||
$this->_values[$this->name][$firstName],
|
|
||||||
$names[1],
|
|
||||||
$value
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$this->_values[$this->name][$firstName] = $value;
|
$this->_values[$this->name][$name] = $value;
|
||||||
}
|
}
|
||||||
$this->_write('[' . $firstName . ']', $this->_values[$this->name][$firstName]);
|
$this->_write('[' . $name . ']', $value);
|
||||||
}
|
}
|
||||||
$this->_encrypted = true;
|
$this->_encrypted = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,24 @@ class CookieComponentTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that replacing scalar with array works.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReplaceScalarWithArray() {
|
||||||
|
$this->Cookie->write('foo', 1);
|
||||||
|
$this->Cookie->write('foo.bar', 2);
|
||||||
|
|
||||||
|
$data = $this->Cookie->read();
|
||||||
|
$expected = array(
|
||||||
|
'foo' => array(
|
||||||
|
'bar' => 2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testReadingCookieValue
|
* testReadingCookieValue
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue