From 6b8ec50148909938850b5acfd11725ae23a8e31b Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Wed, 31 May 2023 09:40:06 +0200 Subject: [PATCH] Fix PHP 8.1 "preg_match(null)" exception when cloning a repository with no URI set Summary: `preg_match()` does not accept passing null as the `$subject` string parameter in PHP 8.1. Thus add a `phutil_nonempty_string()` check if the `$subject` parameter is a non-empty string. 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. ``` EXCEPTION: (RuntimeException) preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=arcpatch-D25250, ref.master=18554ea76ceb, ref.arcpatch-D25250=fade4603a799), phorge(head=diffusionEmptyBranchHistory, ref.master=e11c5486c92b, ref.diffusionEmptyBranchHistory=76f042e4b969) #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/diffusion/request/DiffusionGitRequest.php:6] ``` Closes T15435 Test Plan: After applying this change, try to "Clone" a Repository with no URI set shows the overlay dialog `Clone Repository - Repository has no URIs set.` as expected. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15435 Differential Revision: https://we.phorge.it/D25266 --- src/applications/diffusion/request/DiffusionGitRequest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/applications/diffusion/request/DiffusionGitRequest.php b/src/applications/diffusion/request/DiffusionGitRequest.php index a283fff206..16953f5996 100644 --- a/src/applications/diffusion/request/DiffusionGitRequest.php +++ b/src/applications/diffusion/request/DiffusionGitRequest.php @@ -3,6 +3,9 @@ final class DiffusionGitRequest extends DiffusionRequest { protected function isStableCommit($symbol) { + if ($symbol === null) { + return false; + } return preg_match('/^[a-f0-9]{40}\z/', $symbol); } -- 2.51.2