From 1dd9609beddbda1634e7527b6182a689755a1cbb Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Wed, 31 May 2023 09:38:22 +0200 Subject: [PATCH] Fix PHP 8.1 "preg_match(null)" exception which blocks rendering the "Browse Herald Rules" dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: `preg_match()` does not accept passing null as the `$subject` string parameter in PHP 8.1. Thus first check that `$subject !== null`. ``` EXCEPTION: (RuntimeException) preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=master, ref.master=0e32dbc1ac8f), phorge(head=diffusionRepoPage, ref.master=5405134fa5db, ref.diffusionRepoPage=dbe5e3a68c41) #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/error/PhutilErrorHandler.php:261] #1 <#2> preg_match(string, NULL) called at [/src/applications/herald/typeahead/HeraldRuleDatasource.php:25] ``` Closes T15422 Test Plan: Applied this change; afterwards on the "Diffusion 🡒 Push Logs 🡒 Advanced Search" page at `/diffusion/pushlog/?repositories=PHID-REPO-someRepositoryString`, clicking the search icon for the "Blocked By" field correctly renders.the "Browse Herald Rules" overlay dialog, listing available Herald rules. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15422 Differential Revision: https://we.phorge.it/D25248 --- src/applications/herald/typeahead/HeraldRuleDatasource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/herald/typeahead/HeraldRuleDatasource.php b/src/applications/herald/typeahead/HeraldRuleDatasource.php index 88343bd433..6b73bc0ab6 100644 --- a/src/applications/herald/typeahead/HeraldRuleDatasource.php +++ b/src/applications/herald/typeahead/HeraldRuleDatasource.php @@ -22,7 +22,7 @@ final class HeraldRuleDatasource $query = id(new HeraldRuleQuery()) ->setViewer($viewer); - if (preg_match('/^[hH]\d+\z/', $raw_query)) { + if (($raw_query !== null) && preg_match('/^[hH]\d+\z/', $raw_query)) { $id = trim($raw_query, 'hH'); $id = (int)$id; $query->withIDs(array($id)); -- 2.51.2