BryanDavis has uploaded a new change for review. https://gerrit.wikimedia.org/r/266547
Change subject: Avoid false "added in both Session and $_SESSION" when value is null ...................................................................... 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 --- M includes/session/PHPSessionHandler.php M tests/phpunit/includes/session/PHPSessionHandlerTest.php 2 files changed, 4 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/47/266547/1 diff --git a/includes/session/PHPSessionHandler.php b/includes/session/PHPSessionHandler.php index 5344321..d21bea9 100644 --- a/includes/session/PHPSessionHandler.php +++ b/includes/session/PHPSessionHandler.php @@ -258,7 +258,7 @@ $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 @@ // (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 5a5df6f..125e1b6 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -223,6 +223,7 @@ $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 @@ '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', -- To view, visit https://gerrit.wikimedia.org/r/266547 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I794f0ec793fc91ec68393443f839cfc8a154613e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: wmf/1.27.0-wmf.11 Gerrit-Owner: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits