Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/232263

Change subject: Add proper null check to ChangeRow
......................................................................

Add proper null check to ChangeRow

Both json_decode and unserialize calls are *not* guaranteed to return
an array. But the methods says so. A lot of the places calling this
method assume it returns an array. This can be fixed in two ways:
Either add an is_array check everywhere or fall back to an empty
array(). I'm doing the later here.

Bug: 108246
Change-Id: Id416f19d75d17869a2e84b50a48411f0f1037ad7
---
M lib/includes/changes/ChangeRow.php
M lib/includes/changes/DiffChange.php
2 files changed, 2 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/63/232263/1

diff --git a/lib/includes/changes/ChangeRow.php 
b/lib/includes/changes/ChangeRow.php
index 88a83cf..0b61cd4 100644
--- a/lib/includes/changes/ChangeRow.php
+++ b/lib/includes/changes/ChangeRow.php
@@ -176,10 +176,6 @@
        protected function getInfo( $cache = 'no' ) {
                $info = $this->getField( 'info' );
 
-               if ( !is_array( $info ) ) {
-                       $info = array();
-               }
-
                if ( $cache === 'cache' ) {
                        $this->setField( 'info', $info );
                }
@@ -260,6 +256,7 @@
 
                if ( !is_array( $info ) ) {
                        wfLogWarning( "Failed to unserializeInfo of id: " . 
$this->getObjectId() );
+                       return array();
                }
 
                return $info;
diff --git a/lib/includes/changes/DiffChange.php 
b/lib/includes/changes/DiffChange.php
index 3c12445..c37b0e2 100644
--- a/lib/includes/changes/DiffChange.php
+++ b/lib/includes/changes/DiffChange.php
@@ -43,7 +43,7 @@
         */
        public function hasDiff() {
                $info = $this->getField( 'info' );
-               return !empty( $info ) && isset( $info['diff'] );
+               return isset( $info['diff'] );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/232263
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id416f19d75d17869a2e84b50a48411f0f1037ad7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to