Skip to content

Commit

Permalink
Merge pull request #5232 from google/enhancement/4481-fix-response-shape
Browse files Browse the repository at this point in the history
Fix the shape of sharing settings response to always be an object.
  • Loading branch information
techanvil authored May 19, 2022
2 parents 47ab905 + c158b62 commit a16315e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion includes/Core/Modules/REST_Dashboard_Sharing_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ function ( $new_owner_id, $module_slug ) use ( $original_module_owners ) {
return new WP_REST_Response(
array(
'settings' => $new_sharing_settings,
'newOwnerIDs' => $changed_module_owners,
// Cast array to an object so JSON encoded response is always an object,
// even when the array is empty.
'newOwnerIDs' => (object) $changed_module_owners,
)
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function test_get_rest_routes__success() {
);
$expected_response = array(
'settings' => $expected_sharing_settings,
'newOwnerIDs' => array(
'newOwnerIDs' => (object) array(
// ownerID should be updated as settings have changed.
'pagespeed-insights' => $admin_2->ID,
),
Expand Down

0 comments on commit a16315e

Please sign in to comment.