From 7bbd657c19c49f8d1ff1bd6382ff5f1df2d7bdcd Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 12 Jun 2023 21:50:14 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception when Diffusion repository has no tags 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. ``` EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/src/error/PhutilErrorHandler.php:261] arcanist(head=diffusionEmptyRepoPatternSearch, ref.master=97e163187418, ref.diffusionEmptyRepoPatternSearch=97e163187418), phorge(head=master, ref.master=108cbcd09bd3) #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/applications/diffusion/controller/DiffusionTagListController.php:28] ``` Closes T15461 Test Plan: After applying this line, get the expected `CommandException: Command failed with error #128!` due to ` fatal: detected dubious ownership in repository at '/var/repo/1'` (plus a `RuntimeException: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated` as a bonus), instead of the previous RuntimeException about `strlen()`. Reviewers: O1 Blessed Committers, speck Reviewed By: O1 Blessed Committers, speck Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15461 Differential Revision: https://we.phorge.it/D25285 --- .../diffusion/controller/DiffusionTagListController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/applications/diffusion/controller/DiffusionTagListController.php b/src/applications/diffusion/controller/DiffusionTagListController.php index 15b8dc93ae..ffc6a1a9ef 100644 --- a/src/applications/diffusion/controller/DiffusionTagListController.php +++ b/src/applications/diffusion/controller/DiffusionTagListController.php @@ -25,7 +25,7 @@ final class DiffusionTagListController extends DiffusionController { 'offset' => $pager->getOffset(), ); - if (strlen($drequest->getSymbolicCommit())) { + if (phutil_nonempty_string($drequest->getSymbolicCommit())) { $is_commit = true; $params['commit'] = $drequest->getSymbolicCommit(); } else {