From 46a565d6b00174e631d2022b47677e1a78e73897 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 26 Jan 2016 13:21:57 -0500 Subject: [PATCH] Avoid false "added in both Session and $_SESSION" when value is null Needs to use array_key_exists(), not isset(). Bug: T124371 Change-Id: I794f0ec793fc91ec68393443f839cfc8a154613e --- includes/session/PHPSessionHandler.php | 4 ++-- tests/phpunit/includes/session/PHPSessionHandlerTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/session/PHPSessionHandler.php b/includes/session/PHPSessionHandler.php index 53443211f0..d21bea988c 100644 --- a/includes/session/PHPSessionHandler.php +++ b/includes/session/PHPSessionHandler.php @@ -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 ) ) { diff --git a/tests/phpunit/includes/session/PHPSessionHandlerTest.php b/tests/phpunit/includes/session/PHPSessionHandlerTest.php index 5a5df6f2f3..125e1b664e 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -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', -- 2.20.1