From a5d8b2d5cfd6e809f82556c9f1462ae0035e2279 Mon Sep 17 00:00:00 2001 From: bob Date: Thu, 17 Aug 2023 10:16:24 +0200 Subject: [PATCH] Fix a PHP 8.1 deprecated use of preg_match with a NULL argument Summary: These calls are preventing users to browse subversion/mercurial repositories in PHP 8.1+. Indeed, a similar bug affecting git repositories was already addressed in another commit (rP6b8ec50148909938850b5acfd11725ae23a8e31b). This commit harmonize both DiffusionSvnRequest and DiffusionMercurialRequest with DiffusionGitRequest Fix T15607 Test Plan: - Sign in - Open a diffusion SVN/Mercurial repository - You should not get a RuntimeException concerning this preg_match call Reviewers: O1 Blessed Committers, Sten, valerio.bozzolan Reviewed By: O1 Blessed Committers, Sten, valerio.bozzolan Subscribers: Sten, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15607 Differential Revision: https://we.phorge.it/D25397 --- .../diffusion/request/DiffusionMercurialRequest.php | 5 +++-- src/applications/diffusion/request/DiffusionSvnRequest.php | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/applications/diffusion/request/DiffusionMercurialRequest.php b/src/applications/diffusion/request/DiffusionMercurialRequest.php index b626d62750..676dc097f7 100644 --- a/src/applications/diffusion/request/DiffusionMercurialRequest.php +++ b/src/applications/diffusion/request/DiffusionMercurialRequest.php @@ -3,6 +3,9 @@ final class DiffusionMercurialRequest extends DiffusionRequest { protected function isStableCommit($symbol) { + if ($symbol === null) { + return false; + } return preg_match('/^[a-f0-9]{40}\z/', $symbol); } @@ -10,11 +13,9 @@ final class DiffusionMercurialRequest extends DiffusionRequest { if ($this->branch) { return $this->branch; } - if ($this->repository) { return $this->repository->getDefaultBranch(); } - throw new Exception(pht('Unable to determine branch!')); } diff --git a/src/applications/diffusion/request/DiffusionSvnRequest.php b/src/applications/diffusion/request/DiffusionSvnRequest.php index 5f50366331..33fc3446f9 100644 --- a/src/applications/diffusion/request/DiffusionSvnRequest.php +++ b/src/applications/diffusion/request/DiffusionSvnRequest.php @@ -3,6 +3,9 @@ final class DiffusionSvnRequest extends DiffusionRequest { protected function isStableCommit($symbol) { + if ($symbol === null) { + return false; + } return preg_match('/^[1-9]\d*\z/', $symbol); }