From 8f669ea08289d144dfba24f19c6c94e2e444979d Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 1 May 2023 22:31:09 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions which block rendering the People page Summary: `strlen()` was used in Phabricator to check if a generic value is a non-empty string. This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a general replacement. Note: this may highlight other absurd input values that might be worth correcting instead of just ignoring. If phutil_nonempty_string() throws an exception in your instance, report it to Phorge to evaluate and fix that specific corner case. Use `phutil_nonempty_scalar()` instead in `PhabricatorSearchDateField.php` as input could only be integer instead of string. Closes T15297 Test Plan: Applied these four changes (on top of D25144, D25145, D25146) and `/people/` finally rendered in web browser. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15297 Differential Revision: https://we.phorge.it/D25147 --- .../controller/PhabricatorFileDataController.php | 2 +- .../search/field/PhabricatorSearchDateField.php | 4 ++-- src/view/layout/AphrontSideNavFilterView.php | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/applications/files/controller/PhabricatorFileDataController.php b/src/applications/files/controller/PhabricatorFileDataController.php index 0cc12a85ec..b292b6f4b8 100644 --- a/src/applications/files/controller/PhabricatorFileDataController.php +++ b/src/applications/files/controller/PhabricatorFileDataController.php @@ -29,7 +29,7 @@ final class PhabricatorFileDataController extends PhabricatorFileController { $request_kind = $request->getURIData('kind'); $is_download = ($request_kind === 'download'); - if (!strlen($alt) || $main_domain == $alt_domain) { + if (!phutil_nonempty_string($alt) || $main_domain == $alt_domain) { // No alternate domain. $should_redirect = false; $is_alternate_domain = false; diff --git a/src/applications/search/field/PhabricatorSearchDateField.php b/src/applications/search/field/PhabricatorSearchDateField.php index 41decd9503..8f43494222 100644 --- a/src/applications/search/field/PhabricatorSearchDateField.php +++ b/src/applications/search/field/PhabricatorSearchDateField.php @@ -17,7 +17,7 @@ final class PhabricatorSearchDateField } protected function validateControlValue($value) { - if (!strlen($value)) { + if (!phutil_nonempty_scalar($value)) { return; } @@ -32,7 +32,7 @@ final class PhabricatorSearchDateField } protected function parseDateTime($value) { - if (!strlen($value)) { + if (!phutil_nonempty_scalar($value)) { return null; } diff --git a/src/view/layout/AphrontSideNavFilterView.php b/src/view/layout/AphrontSideNavFilterView.php index 6d255f2b30..c7c8b5b534 100644 --- a/src/view/layout/AphrontSideNavFilterView.php +++ b/src/view/layout/AphrontSideNavFilterView.php @@ -92,12 +92,21 @@ final class AphrontSideNavFilterView extends AphrontView { return $this->getMenuView()->getItem($key); } + /** + * Add a thing in the menu + * + * @param string $key Internal name + * @param string $name Human name + * @param mixed $uri Destination URI. For example as string or as PhutilURI. + * @param string $type Item type. For example see PHUIListItemView constants. + * @param string $icon Icon name + */ private function addThing($key, $name, $uri, $type, $icon = null) { $item = id(new PHUIListItemView()) ->setName($name) ->setType($type); - if (strlen($icon)) { + if (phutil_nonempty_string($icon)) { $item->setIcon($icon); }