From dd24c94b0741ae2c3fdf73d6e70d0a10e18ba010 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 2 Jun 2023 20:39:54 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions block creating a diff in Differential web interface 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=master, ref.master=18554ea76ceb), phorge(head=diffDiff, ref.master=e11c5486c92b, ref.diffDiff=e11c5486c92b) #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php:160] ``` Closes T15430 Test Plan: After applying these two changes, going to `/differential/diff/create/`, pasting the content of a diff file into the "Raw Diff" field, and selecting the "Create Diff" button, `/differential/diff/1/` rendered correctly in web browser. Also, install xdebug and try again with coverage mode enabled in your php.ini of your PHP cli. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15430 Differential Revision: https://we.phorge.it/D25262 --- .../diff/view/PHUIDiffTableOfContentsItemView.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php index f705fa4377..752d895952 100644 --- a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php +++ b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php @@ -42,6 +42,11 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView { return $this; } + /** + * Get the Coverage, expressed as a string, each letter with this meaning: + * N: Not Executable, C: Covered, U: Uncovered. + * @return string|null + */ public function getCoverage() { return $this->coverage; } @@ -139,7 +144,7 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView { $not_applicable = '-'; $coverage = $this->getCoverage(); - if (!strlen($coverage)) { + if (!phutil_nonempty_string($coverage)) { return $not_applicable; } @@ -157,7 +162,7 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView { $not_applicable = '-'; $coverage = $this->getCoverage(); - if (!strlen($coverage)) { + if (!phutil_nonempty_string($coverage)) { return $not_applicable; }