Permalink
Browse files

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

  • Loading branch information...
1 parent a96659b commit 417c03716c84f83dc03b06dcd5c25b5c519695a8 @chillu chillu committed Jun 17, 2012
Showing with 16 additions and 2 deletions.
  1. +9 −2 control/Session.php
  2. +7 −0 tests/control/SessionTest.php
View
@@ -295,13 +295,20 @@ public function inst_set($name, $val) {
// 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 @@ function testGetAllElements() {
$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.
*/

0 comments on commit 417c037

Please sign in to comment.