From aea1d473795427a83ec4e3ad2c9f5ac56fef0318 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 1 May 2023 22:28:57 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" and "array_slice(null)" exceptions which block typeahead completion proposals 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. `array_slice()` no longer accepts passing `null` as a parameter. This behavior is deprecated since PHP 8.1. Adding an if clause; not using a Null Coalescing Operator (PHP 7+) as Phorge currently still supports PHP 5.5. Closes T15321 Test Plan: Applied these two changes on top of D25147. Afterwards, typeahead autocompletion proposal dropdowns for the three fields "Assigned To", "Subscribers", "Tags" got displayed 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: T15321 Differential Revision: https://we.phorge.it/D25170 --- .../PhabricatorTypeaheadModularDatasourceController.php | 2 +- .../datasource/PhabricatorTypeaheadCompositeDatasource.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php index 2d55c5f663..5753c3cded 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php @@ -39,7 +39,7 @@ final class PhabricatorTypeaheadModularDatasourceController $parameters = array(); $raw_parameters = $request->getStr('parameters'); - if (strlen($raw_parameters)) { + if (phutil_nonempty_string($raw_parameters)) { try { $parameters = phutil_json_decode($raw_parameters); } catch (PhutilJSONParserException $ex) { diff --git a/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php b/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php index 5594044c42..d344425d30 100644 --- a/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php +++ b/src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php @@ -207,7 +207,11 @@ abstract class PhabricatorTypeaheadCompositeDatasource } protected function sliceResults(array $results) { - $offset = $this->getOffset(); + if ($this->getOffset()) { + $offset = $this->getOffset(); + } else { + $offset = 0; + } $limit = $this->getLimit(); if ($offset || $limit) {