jenkins-bot has submitted this change and it was merged.

Change subject: Make sure bundledNotifications is an array
......................................................................


Make sure bundledNotifications is an array

- Make sure that even if internal values of the array are null,
  the end-result is a valid array (with sequential keys)
- Verify that the API sent the UI an actual array, and if not,
  output an error to the console.

Bug: T145825
Change-Id: Ibdf17c58fe88e3e2547dde62cd4d3d06e089cbc8
---
M includes/DataOutputFormatter.php
M modules/controller/mw.echo.Controller.js
2 files changed, 13 insertions(+), 3 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/DataOutputFormatter.php b/includes/DataOutputFormatter.php
index d7b866e..f00013f 100644
--- a/includes/DataOutputFormatter.php
+++ b/includes/DataOutputFormatter.php
@@ -142,14 +142,14 @@
                        $output['*'] = $formatted;
 
                        if ( $notification->getBundledNotifications() && 
self::isBundleExpandable( $event->getType() ) ) {
-                               $output['bundledNotifications'] = array_filter( 
array_map( function ( EchoNotification $notification ) use ( $format, $user, 
$lang ) {
+                               $output['bundledNotifications'] = array_values( 
array_filter( array_map( function ( EchoNotification $notification ) use ( 
$format, $user, $lang ) {
                                        // remove nested notifications to
                                        //   - ensure they are formatted as 
single notifications (not bundled)
                                        //   - prevent further re-entrance on 
the current notification
                                        $notification->setBundledNotifications( 
array() );
                                        
$notification->getEvent()->setBundledEvents( array() );
                                        return self::formatOutput( 
$notification, $format, $user, $lang );
-                               }, array_merge( array( $notification ), 
$notification->getBundledNotifications() ) ) );
+                               }, array_merge( array( $notification ), 
$notification->getBundledNotifications() ) ) ) );
                        }
                }
 
diff --git a/modules/controller/mw.echo.Controller.js 
b/modules/controller/mw.echo.Controller.js
index 59cb771..9ea2e27 100644
--- a/modules/controller/mw.echo.Controller.js
+++ b/modules/controller/mw.echo.Controller.js
@@ -315,7 +315,8 @@
                                                                        
notifData.sources[ source ]
                                                                );
                                                        }
-                                               } else if ( 
newNotifData.bundledNotifications ) {
+
+                                               } else if ( Array.isArray( 
newNotifData.bundledNotifications ) ) {
                                                        // local bundle
                                                        newNotifData.modelName 
= 'bundle_' + notifData.id;
                                                        itemModel = new 
mw.echo.dm.BundleNotificationItem(
@@ -333,6 +334,15 @@
 
                                                        idArray.push( 
notifData.id );
                                                        localItems.push( 
itemModel );
+
+                                                       if ( 
newNotifData.bundledNotifications ) {
+                                                               // This means 
that bundledNotifications is truthy
+                                                               // but is not 
an array. We should log this in the console
+                                                               mw.log.warn(
+                                                                       
'newNotifData.bundledNotifications is expected to be an array,' +
+                                                                       'but 
instead received "' + $.type( newNotifData.bundledNotifications ) + '"'
+                                                               );
+                                                       }
                                                }
 
                                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibdf17c58fe88e3e2547dde62cd4d3d06e089cbc8
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Mattflaschen <mflasc...@wikimedia.org>
Gerrit-Reviewer: Sbisson <sbis...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to