From a5384ca60470e56a5312d5a7147ddd3ffa2e75d8 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Thu, 5 Dec 2024 23:37:18 +0100 Subject: [PATCH] Hovercards: Avoid "Undefined index: objectPHID" when passing bogus data Summary: Do not throw an exception when passing bogus parameters to hovercards but properly handle the missing array index by setting `$object_phid` to `null`. In consequence, see a proper hovercard correctly displaying `Unknown Object (????)` instead of an exception. Closes T15969 Test Plan: * Go to http://phorge.localhost/search/hovercard/?cards={"whatever":{"whatever":"foobar"}} or http://phorge.localhost/?__path__=%2fsearch%2fhovercard%2f&cards={%22whatever%22:{%22whatever%22:%22foobar%22}} and see a nice `Unknown Object (????)` instead of an ugly exception * Go to http://phorge.localhost/search/hovercard/?cards={%22PHID-TASK-12345678%2F%22%3A{%22objectPHID%22%3A%22PHID-TASK-12345678%22%2C%22contextPHID%22%3Anull}} (make sure to use a valid task PHID) and still see a correct hovercard rendered Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15969 Differential Revision: https://we.phorge.it/D25849 --- .../search/controller/PhabricatorSearchHovercardController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/search/controller/PhabricatorSearchHovercardController.php b/src/applications/search/controller/PhabricatorSearchHovercardController.php index 3c9d6b6a54..1f0fa13f4d 100644 --- a/src/applications/search/controller/PhabricatorSearchHovercardController.php +++ b/src/applications/search/controller/PhabricatorSearchHovercardController.php @@ -98,7 +98,7 @@ final class PhabricatorSearchHovercardController $results = array(); foreach ($cards as $card_key => $card) { - $object_phid = $card['objectPHID']; + $object_phid = idx($card, 'objectPHID'); $handle = $handles[$object_phid]; $object = idx($objects, $object_phid);