From 524dc83b4e8c9ed84954e91c17b68013994f9853 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 20 May 2023 17:48:31 +0200 Subject: [PATCH] Fix PHP 8.1 null parameter exceptions which block rendering the "Browse Projects" overlay dialog 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 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. Similarly, passing `null` to the `$haystack` parameter of `strpos()` is deprecated in PHP 8.1. Similarly, passing `null` to the `$string` parameter of `ltrim()` is deprecated in PHP 8.1. Closes part of T15335 Test Plan: Applied these four changes in Phorge (plus the one change in D25180 in Arcanist) and the `Browse Projects` overlay dialog finally rendered in web browser and listed existing projects. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15335 Differential Revision: https://we.phorge.it/D25179 --- .../project/typeahead/PhabricatorProjectDatasource.php | 6 ++++-- .../datasource/PhabricatorTypeaheadCompositeDatasource.php | 2 +- .../typeahead/datasource/PhabricatorTypeaheadDatasource.php | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/applications/project/typeahead/PhabricatorProjectDatasource.php b/src/applications/project/typeahead/PhabricatorProjectDatasource.php index 5953f688d2..86478a5e1e 100644 --- a/src/applications/project/typeahead/PhabricatorProjectDatasource.php +++ b/src/applications/project/typeahead/PhabricatorProjectDatasource.php @@ -21,7 +21,9 @@ final class PhabricatorProjectDatasource $raw_query = $this->getRawQuery(); // Allow users to type "#qa" or "qa" to find "Quality Assurance". - $raw_query = ltrim($raw_query, '#'); + if ($raw_query !== null) { + $raw_query = ltrim($raw_query, '#'); + } $tokens = self::tokenizeString($raw_query); $query = id(new PhabricatorProjectQuery()) @@ -142,7 +144,7 @@ final class PhabricatorProjectDatasource $proj_result->addAttribute($proj->getDisplayIconName()); $description = idx($descriptions, $phid); - if (strlen($description)) { + if (phutil_nonempty_string($description)) { $summary = PhabricatorMarkupEngine::summarizeSentence($description); $proj_result->addAttribute($summary); } diff --git a/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php b/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php index d344425d30..8a396c1ed3 100644 --- a/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php +++ b/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php @@ -28,7 +28,7 @@ abstract class PhabricatorTypeaheadCompositeDatasource // We only need to do a prefix phase query if there's an actual query // string. If the user didn't type anything, nothing can possibly match it. - if (strlen($this->getRawQuery())) { + if (phutil_nonempty_string($this->getRawQuery())) { $phases[] = self::PHASE_PREFIX; } diff --git a/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php b/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php index 29a8d4b7ba..a35a8e8f0f 100644 --- a/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php +++ b/src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php @@ -464,7 +464,11 @@ abstract class PhabricatorTypeaheadDatasource extends Phobject { // We're looking for a "(" so that a string like "members(q" is identified // and parsed as a function call. This allows us to start generating // results immediately, before the user fully types out "members(quack)". - return (strpos($token, '(') !== false); + if ($token) { + return (strpos($token, '(') !== false); + } else { + return false; + } }