Permalink
Browse files

Fix fatal error thrown when replacing scalar with array

Refs #11280
  • Loading branch information...
chinpei215 committed Oct 6, 2017
1 parent b3d83af commit 959f45a6c68e0d0277869510b936779a43f42e8f
@@ -229,27 +229,14 @@ public function write($key, $value = null, $encrypt = true, $expires = null) {
}
foreach ($key as $name => $value) {
$names = array($name);
if (strpos($name, '.') !== false) {
$names = explode('.', $name, 2);
}
$firstName = $names[0];
$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
);
$this->_values[$this->name] = Hash::insert($this->_values[$this->name], $name, $value);
list($name) = explode('.', $name, 2);
$value = $this->_values[$this->name][$name];
} 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;
}
@@ -429,6 +429,24 @@ public function testWriteMixedArray() {
$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
*

0 comments on commit 959f45a

Please sign in to comment.