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
This commit is contained in:
Brad Jorsch 2016-01-26 13:21:57 -05:00
parent 3e9d3ec8c2
commit 46a565d6b0
2 changed files with 4 additions and 2 deletions

View 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 ) ) {

View 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',