From 313d3b7bf2ea3aaee587c2af73bf2afa3858f696 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 1 May 2023 15:51:48 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions which block rendering the Maniphest task creation page 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. Closes T15302 Test Plan: Applied these five changes (on top of D25144, D25145, D25146, D25147, D25151) and `/maniphest/task/edit/form/default/` finally rendered in web browser. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15302 Differential Revision: https://we.phorge.it/D25152 --- .../transactions/editengine/PhabricatorEditEngine.php | 6 +++--- .../transactions/editfield/PhabricatorEditField.php | 2 +- .../transactions/editfield/PhabricatorTextEditField.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index 3ebf6377f2..f70e172a99 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -971,14 +971,14 @@ abstract class PhabricatorEditEngine } $page_key = $request->getURIData('pageKey'); - if (!strlen($page_key)) { + if (!phutil_nonempty_string($page_key)) { $pages = $this->getPages($object); if ($pages) { $page_key = head_key($pages); } } - if (strlen($page_key)) { + if (phutil_nonempty_string($page_key)) { $page = $this->selectPage($object, $page_key); if (!$page) { return new Aphront404Response(); @@ -1169,7 +1169,7 @@ abstract class PhabricatorEditEngine if ($this->getIsCreate()) { $template = $request->getStr('template'); - if (strlen($template)) { + if (phutil_nonempty_string($template)) { $template_object = $this->newObjectFromIdentifier( $template, array( diff --git a/src/applications/transactions/editfield/PhabricatorEditField.php b/src/applications/transactions/editfield/PhabricatorEditField.php index 7eafbc60cf..4457e03bae 100644 --- a/src/applications/transactions/editfield/PhabricatorEditField.php +++ b/src/applications/transactions/editfield/PhabricatorEditField.php @@ -418,7 +418,7 @@ abstract class PhabricatorEditField extends Phobject { } $instructions = $this->getControlInstructions(); - if (strlen($instructions)) { + if (phutil_nonempty_string($instructions)) { $form->appendRemarkupInstructions($instructions); } diff --git a/src/applications/transactions/editfield/PhabricatorTextEditField.php b/src/applications/transactions/editfield/PhabricatorTextEditField.php index 68854cf2e2..d915d4db75 100644 --- a/src/applications/transactions/editfield/PhabricatorTextEditField.php +++ b/src/applications/transactions/editfield/PhabricatorTextEditField.php @@ -18,7 +18,7 @@ final class PhabricatorTextEditField $control = new AphrontFormTextControl(); $placeholder = $this->getPlaceholder(); - if (strlen($placeholder)) { + if (phutil_nonempty_string($placeholder)) { $control->setPlaceholder($placeholder); }