From e65ac7b8800d3397abfced7824a8d316ec573d8f Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sun, 30 Apr 2023 18:24:18 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions which block rendering the Conpherence 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 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. Closes T15304 Test Plan: Applied these four changes (on top of `D25144`, `D25145`, `D25146`, `D25147`, `D25150`, `D25151`, `D25152`, `D25153`) and `/conpherence/` page 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: T15304 Differential Revision: https://we.phorge.it/D25154 --- .../conpherence/query/ConpherenceThreadQuery.php | 7 ++++--- .../conpherence/query/ConpherenceThreadSearchEngine.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/applications/conpherence/query/ConpherenceThreadQuery.php b/src/applications/conpherence/query/ConpherenceThreadQuery.php index 99fd18878e..34bbf7e6b0 100644 --- a/src/applications/conpherence/query/ConpherenceThreadQuery.php +++ b/src/applications/conpherence/query/ConpherenceThreadQuery.php @@ -135,7 +135,8 @@ final class ConpherenceThreadQuery } protected function buildGroupClause(AphrontDatabaseConnection $conn_r) { - if ($this->participantPHIDs !== null || strlen($this->fulltext)) { + if ($this->participantPHIDs !== null || + phutil_nonempty_string($this->fulltext)) { return qsprintf($conn_r, 'GROUP BY thread.id'); } else { return $this->buildApplicationSearchGroupClause($conn_r); @@ -152,7 +153,7 @@ final class ConpherenceThreadQuery id(new ConpherenceParticipant())->getTableName()); } - if (strlen($this->fulltext)) { + if (phutil_nonempty_string($this->fulltext)) { $joins[] = qsprintf( $conn, 'JOIN %T idx ON idx.threadPHID = thread.phid', @@ -234,7 +235,7 @@ final class ConpherenceThreadQuery $this->participantPHIDs); } - if (strlen($this->fulltext)) { + if (phutil_nonempty_string($this->fulltext)) { $where[] = qsprintf( $conn, 'MATCH(idx.corpus) AGAINST (%s IN BOOLEAN MODE)', diff --git a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php index cbaf43b0a9..77e54157cf 100644 --- a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php +++ b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php @@ -106,7 +106,7 @@ final class ConpherenceThreadSearchEngine $engines = array(); $fulltext = $query->getParameter('fulltext'); - if (strlen($fulltext) && $conpherences) { + if (phutil_nonempty_string($fulltext) && $conpherences) { $context = $this->loadContextMessages($conpherences, $fulltext); $author_phids = array();