Avoid false "added in both Session and $_SESSION" when value is null
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 26 Jan 2016 18:21:57 +0000 (13:21 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 26 Jan 2016 18:21:57 +0000 (13:21 -0500)
Needs to use array_key_exists(), not isset().

Bug: T124371
Change-Id: I794f0ec793fc91ec68393443f839cfc8a154613e

includes/session/PHPSessionHandler.php
tests/phpunit/includes/session/PHPSessionHandlerTest.php

index 5344321..d21bea9 100644 (file)
@@ -258,7 +258,7 @@ class PHPSessionHandler {
                $changed = false;
                $cache = isset( $this->sessionFieldCache[$id] ) ? $this->sessionFieldCache[$id] : array();
                foreach ( $data as $key => $value ) {
-                       if ( !isset( $cache[$key] ) ) {
+                       if ( !array_key_exists( $key, $cache ) ) {
                                if ( $session->exists( $key ) ) {
                                        // New in both, so ignore and log
                                        $this->logger->warning(
@@ -293,7 +293,7 @@ class PHPSessionHandler {
                // (but not if $_SESSION can't represent it at all)
                \Wikimedia\PhpSessionSerializer::setLogger( new \Psr\Log\NullLogger() );
                foreach ( $cache as $key => $value ) {
-                       if ( !isset( $data[$key] ) && $session->exists( $key ) &&
+                       if ( !array_key_exists( $key, $data ) && $session->exists( $key ) &&
                                \Wikimedia\PhpSessionSerializer::encode( array( $key => true ) )
                        ) {
                                if ( $cache[$key] === $session->get( $key ) ) {
index 5a5df6f..125e1b6 100644 (file)
@@ -223,6 +223,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase {
 
                $session = $manager->getEmptySession();
                $session->set( 'Unchanged', 'setup' );
+               $session->set( 'Unchanged, null', null );
                $session->set( 'Changed in $_SESSION', 'setup' );
                $session->set( 'Changed in Session', 'setup' );
                $session->set( 'Changed in both', 'setup' );
@@ -260,6 +261,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase {
                        'Added in $_SESSION' => '$_SESSION',
                        'Added in both' => 'Session',
                        'Unchanged' => 'setup',
+                       'Unchanged, null' => null,
                        'Changed in Session' => 'Session',
                        'Changed in $_SESSION' => '$_SESSION',
                        'Changed in both' => 'Session',