BUGFIX Avoid Session::set() clearing on existing val (fixes #7487)

This commit is contained in:
Ingo Schommer 2012-06-17 23:46:52 +02:00
parent a96659ba8b
commit 417c03716c
2 changed files with 16 additions and 2 deletions

View File

@ -295,13 +295,20 @@ class Session {
// We still want to do this even if we have strict path checking for legacy code // We still want to do this even if we have strict path checking for legacy code
$var = &$this->data; $var = &$this->data;
$diffVar = &$this->changedData; $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) { foreach($names as $n) {
$var = &$var[$n]; $var = &$var[$n];
$diffVar = &$diffVar[$n];
} }
if($var !== $val) { if($var !== $val) {
foreach($names as $n) {
$diffVar = &$diffVar[$n];
}
$var = $val; $var = $val;
$diffVar = $val; $diffVar = $val;
} }

View File

@ -45,6 +45,13 @@ class SessionTest extends SapphireTest {
$this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2')); $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. * Check that changedData isn't populated with junk when clearing non-existent entries.
*/ */