From 85f51c54303fe50ebc09ee0b652033a8a9f29ab1 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sun, 11 Aug 2024 17:27:59 +0200 Subject: [PATCH] Fix PHP 8.1 "str_replace(null)" exception in DivinerAtomRef Summary: Passing null instead of a string or array to `str_replace()` deprecated since PHP 8.1. Thus do not create a title array with a `null` entry in `DivinerFindController` when there is no `$query_text`, later to be read via `$this->titles` in `DivinerAtomRef`. ``` ERROR 8192: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated at [/var/www/html/phorge/phorge/src/applications/diviner/atom/DivinerAtomRef.php:205] #0 str_replace(string, string, NULL) called at [/src/applications/diviner/atom/DivinerAtomRef.php:205] #1 DivinerAtomRef::normalizeTitleString(NULL) called at [/src/applications/diviner/query/DivinerAtomQuery.php:344] ``` Credits to valerio.bozzolan for finding the right spot in the code. Closes T15911 Test Plan: Go to http://phorge.localhost/diviner/find/ (not passing a `name` URI parameter), optionally with D25768 applied to avoid another exception Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15911 Differential Revision: https://we.phorge.it/D25769 --- src/applications/diviner/controller/DivinerFindController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/applications/diviner/controller/DivinerFindController.php b/src/applications/diviner/controller/DivinerFindController.php index d6ddd420fd..072443ed8c 100644 --- a/src/applications/diviner/controller/DivinerFindController.php +++ b/src/applications/diviner/controller/DivinerFindController.php @@ -58,7 +58,9 @@ final class DivinerFindController extends DivinerController { if (!$atoms) { $title_query = clone $query; - $title_query->withTitles(array($query_text)); + if (phutil_nonempty_string($query_text)) { + $title_query->withTitles(array($query_text)); + } $atoms = $title_query->execute(); }