mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Avoid Session::set() clearing on existing val (fixes #7487)
This commit is contained in:
parent
a96659ba8b
commit
417c03716c
@ -295,13 +295,20 @@ class Session {
|
||||
// We still want to do this even if we have strict path checking for legacy code
|
||||
$var = &$this->data;
|
||||
$diffVar = &$this->changedData;
|
||||
|
||||
|
||||
// Iterate twice over the names - once to see if the value needs to be changed,
|
||||
// and secondly to get the changed data value. This is done to solve a problem
|
||||
// where iterating over the diff var would create empty arrays, and the value
|
||||
// would then not be set, inadvertently clearing session values.
|
||||
foreach($names as $n) {
|
||||
$var = &$var[$n];
|
||||
$diffVar = &$diffVar[$n];
|
||||
}
|
||||
|
||||
if($var !== $val) {
|
||||
foreach($names as $n) {
|
||||
$diffVar = &$diffVar[$n];
|
||||
}
|
||||
|
||||
$var = $val;
|
||||
$diffVar = $val;
|
||||
}
|
||||
|
@ -45,6 +45,13 @@ class SessionTest extends SapphireTest {
|
||||
$this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2'));
|
||||
}
|
||||
|
||||
function testSettingExistingDoesntClear() {
|
||||
$s = new Session(array('something' => array('does' => 'exist')));
|
||||
|
||||
$s->inst_set('something.does', 'exist');
|
||||
$this->assertEquals(array(), $s->inst_changedData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that changedData isn't populated with junk when clearing non-existent entries.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user